C++ Beginner Program Fix it right?

#include <iostream>
#include <conio.h>
#include <iomanip>
#include <cmath>
using namespace std;

int getTestScores();
double calcAverage(double average, double testScores);

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

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

cout << fixed << setprecision(1);
cout << "Average Score is: " << average << endl;
getchar();
return 0;
}

int getTestScores() {
double test1 = 0.0;
double test2 = 0.0;
double test3 = 0.0;
double testScores = 0.0;

cout << "First Test: ";
cin >> test1;
cout << "Second Test: ";
cin >> test2;
cout << "Third Test: ";
cin >> test3;

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

double calcAverage(double averageScore, double testScores){
double averageScores;
averageScore = (double)testScores / 3;
return averageScore;
}


Create a program that calcuates 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. 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.


i know the problem is in the double calcAverage( ) but just dont know exactly what.
Last edited on
You declare and define calcAverage as taking two arguments.

double calcAverage(double average, double testScores);

But in main you call it without any arguments.

average = calcAverage();

Also you don't need the averageScore parameter if you are going to return its value from the function.

Last edited on
.........dont understand.....................
I think he means you have the arithmatic right in the function description using averageScore and testScores as variables, but in the main{ program code here } you call the function calcAverage(withoutInserting, otherVariables) into those locations. That is, the variables you want to be passed to the function, dealt with, and returned with the result
closed account (zb0S216C)
As vin already pointed out, you told the compiler that calcAverage() takes two arguments (values you pass to the function when you invoke (call) it). However, when you call the function, you don't give it anything; therefore, the compiler gives you an error.

Wazzak
Topic archived. No new replies allowed.