I'm working on code for a class i am currently taking. The assignment asks to
"write a C++ program that reads in an unknown number of test scores from the console (up to but not exceeding 100), and stores the values in an array.
Include in the program functions that compute and return the maximum test score, the minimum test score, the midrange of the test scores and the average (mean) of the test scores when called.
Call all functions as needed to produce a console output that includes all individual test scores separated by tabs, the max score, the min score, the midrange of the scores, and the average score."
Im having a really hard time understanding how the functions work. How do i create a function for max, min, average and median?
Then, how do i implement them in my main?
attached below is my code so far (not very good at this stuff yet)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
using namespace std;
int count=0;
int input;
int testScores [100]={input};
int high;
int low;
int min;
int max;
int avg;
int maxVal;
int main ()
{
int count=0;
cout << " Enter first test score. Enter -1 to stop. " << endl;
cin >> input;
while (input != -1)
{
testScores [count]= input;
count++;
cout << " Enter next test score. Enter -1 to stop.\t " << endl;
cin >> input;
}
int maxval (int maximum);
cout << " The maximum value is: " << maxVal << endl;
cout << " The average is: : " << high << endl;
return 0;
}
int maxValue (int maximum)
{
maxVal=0;
int max [100] ;
for ( maxVal = 0; maxVal < max[100]; maxVal++)
{
if (max[100]>maxVal) max[100]=maxVal;
{
return maxVal;
}
}
}
|