Write a program that calculates the average of three test scores. The program sh
ID: 3546302 • Letter: W
Question
Write a program that calculates the average of three test scores. The program should contain
three value-returning functions: main, getTestScore, and calcAverage. The main function should
call the get TestScore function to get, validate the score to make sure the value is between 0 and
100, and return each of the three test score. The testscore may contain a decimal place. (Hint:
the main function will need to call the getTestScore function three times.) The main function
then should call the calcAverage function to calculate and return the average of the three test
scores. When the calAverage function has completed its task, the main function should display
the average on the screen.
Explanation / Answer
#include<iostream>
using namespace std;
double getTestScore()
{
double test = 0;
cout <<"Enter test Score :";
cin >> test;
cout << endl;
while(test<0 || test>100)
{
cout <<"Invalid Score. Enter test Score :";
cin >> test;
cout << endl;
}
return test;
}
double calcAverage(double a, double b,double c)
{
return (a+b+c)/3.0;
}
int main()
{
double testscore1,testscore2,testscore3;
testscore1 = getTestScore();
testscore2 = getTestScore();
testscore3 = getTestScore();
cout << "Average test score given by " << calcAverage(testscore1,testscore2,testscore3) << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.