Write a program that prompts the user to enter five test scores and then print t
ID: 3783023 • Letter: W
Question
Write a program that prompts the user to enter five test scores and then print the average test score to the screen. (Assume that the test scores are decimal numbers). Use the following 5 numbers: 10.5 5.5 20.0 10.0 5.5. I am having trouble understanding where the 5 values are entered in the program.
The program has been provided:
Program to enter and calc avg of 5 test scores then display result to screen
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double testScore1;
double testScore2;
double testScore3;
double testScore4;
double testScore5;
cout << "Enter test score 1: ";
cin >> testScore1;
cout << endl;
cout << "Enter test score 2: ";
cin >> testScore2;
cout << endl;
cout << "Enter test score 3: ";
cin >> testScore3;
cout << endl;
cout << "Enter test score 4: ";
cin >> testScore4;
cout << endl;
cout << "Enter test score 5: ";
cin >> testScore5;
cout << endl;
cout << "Average test score: " << (testScore1+testScore2+testScore3+testScore4+testScore5)/5 << endl;
cout << endl;
// when using Visual Studio, use the system/pause command to display the results of your program
// system("pause");
return 0;
}
Explanation / Answer
Program:
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
double testScore1;
double testScore2;
double testScore3;
double testScore4;
double testScore5;
cout << "Enter test score 1: ";
cin >> testScore1;
cout << endl;
cout << "Enter test score 2: ";
cin >> testScore2;
cout << endl;
cout << "Enter test score 3: ";
cin >> testScore3;
cout << endl;
cout << "Enter test score 4: ";
cin >> testScore4;
cout << endl;
cout << "Enter test score 5: ";
cin >> testScore5;
cout << endl;
cout << "Average test score: " << (testScore1+testScore2+testScore3+testScore4+testScore5)/5 << endl;
cout << endl;
exit(0); /* Here we are adding exit command for the instruction system/pause command to display the results of your program*/
system("pause");
return 0;
}
Output:
Test score 1 is :10.5
Test score 2 is :5.5
Test score 3 is :20.0
Test score 4 is : 10.0
Test score 5 is : 5.5
Average test score: 10.3