C++ program that calculates the average of three test scores
###### Posted by Samath
Last Updated: November 15, 2014

Create a C++ 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 getTestScore function to get and return each of three test scores. The test scores 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 calcAverage function has completed its task, the main function should display the average on the screen. Display the average with one decimal place.

Solution:

```#include <iostream>
#include <iomanip>
using namespace std;
float getTestScore();
float calcAverage(float test1, float test2, float test3);

int main(int argc, char *argv[])
{
float test1;
float test2;
float test3;
float avg;

test1 = getTestScore();
test2 = getTestScore();
test3 = getTestScore();
avg = calcAverage(test1,test2,test3);
cout <<setprecision(3)<<"Average: " << avg << endl;

return 0;
}

float getTestScore()
{
float score;

cout<<"Enter test score: ";
cin>>score;

return score;
}

float calcAverage(float test1, float test2, float test3)
{
float average = (test1+test2+test3)/3;
return average;
}
```
###### How do you write a query to find the average value of a numeric column?
JackBrn | Jun 20, 2024
###### How do you use the AVG function to calculate the average value of a numeric column?
NickCrt | Jul 22, 2024
###### Java program that compute the average test score for a student and assign the appropriate letter grade
Samath | Jan 17, 2024
###### Java program that computes the sum, difference, product, average, distance, maximum and minimum of two numbers
Samath | Feb 08, 2021
###### C++ program that prompts the user to input five decimal numbers, prints the five decimal numbers, converts each decimal number to the nearest integer, adds the five integers and prints the sum and average of the five integers.
Samath | Apr 06, 2022