value-returning functions

For some reason this does not return the average of the three grades please help me figure out why its not returning the correct value.


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

//prototypes
int getTestScores();
double calcAverage(int testScores);

int main()
{
double testScores = 0.0;
double average = 0.0;

testScores = getTestScores();
average = (int) calcAverage;

//display
cout << fixed << setprecision(1);
cout << "Average: " << average << endl;


system("pause");
return 0;


}

//fuction defs

int getTestScores()
{
int test1 = 0;
int test2 = 0;
int test3 = 0;
int testScores = 0;

cout << "Test Score 1: ";
cin >> test1;
cout << "Test Score 2: ";
cin >> test2;
cout << "Test Score 3: ";
cin >> test3;

testScores = test1 + test2 + test3;
return testScores;
}

double calcAverage(int testScores)
{
double averageScore;

averageScore = testScores / 3;
return averageScore;
}//end
Because this one is weird - average = (int) calcAverage; No idea whats happening here.

You want to call the function calcAverage, and send in testScores as parameters.

average = calcAverage(testScores);

That'll fix your problem.

Please if you decide to post in the future. Put all of your code between code tags <>.

http://www.cplusplus.com/articles/jEywvCM9/
Thanks for your help.
Topic archived. No new replies allowed.