I am required to make a program which asks the user for a series of values one at a time. When the User enters the integer 0, the program displays the following information:
-The number of integers in the series, not including 0.
-The average of the integers.
-The largest integer and the smallest integer in the series.
-The difference between the largest and smallest integers.
At the moment, I cannot post what I have so far, as is is on a different computer and I don't have a drive. I would greatly appreciate any help available. I will try to post what I have so far ASAP. Thank You.
#include <iostream>
usingnamespace std;
double findaverage(int intarray[],int arraysize)
{
int total = 0;
for (int x = 0; x < (arraysize - 1); x++)
{
total += intarray[x];
}
return ((double)total/(arraysize - 1));
}
int findsmallest(int intarray[],int arraysize)
{
int smallest = intarray[0];
for (int x = 1; x < (arraysize - 1); x++)
{
if (intarray[x] < intarray[x-1])
{
smallest = intarray[x];
}
}
return smallest;
}
int findlargest(int intarray[],int arraysize)
{
int largest = intarray[0];
for (int x = 1; x < (arraysize - 1); x++)
{
if (intarray[x] > intarray[x-1])
{
largest = intarray[x];
}
}
return largest;
}
void pause(void)
{
cout << "Press any key to exit";
cin.ignore();
cin.get();
}
int main (void)
{
int user_input = 1;
int arraysize = 0;
int intarray[500];
do
{
cout << "Please input a number, 0 to stop (500 max numbers)" << endl;
cin >> user_input;
intarray[arraysize] = user_input;
arraysize++;
} while (user_input != 0);
cout << "The number of ints entered is " << (arraysize - 1) << endl;
cout << "The average is " << findaverage(intarray,arraysize) << endl;
cout << "The smallest is " << findsmallest(intarray,arraysize) << endl;
cout << "The largest is " << findlargest(intarray,arraysize) << endl;
cout << "The difference between the largest and smallest integers is " << (findlargest(intarray,arraysize) - findsmallest(intarray,arraysize)) << endl;
pause();
return 0;
}