Help please, whats wrong with my program. Description is in the post please and thank you.

0 Bob huginstien · April 15, 2015
Write a C++ program that calculates the average of three test scores. The program should contain two value-returning functions (main and CalcAverage) and two void functions (GetTestScores and DisplayAverage). The main function should call the void GetTestScores function to get three test scores. The test scores may contain a decimal place. The main function should then call the value-returning 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 call the void DisplayAverage function to display the average of the three test scores on the screen. Display the average with one decimal place. The following shows a sample run of the program.
 
Enter three test scores: 78.5 91.6 83.4
The average of the three test scores is 84.5


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


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

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

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

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

void getTestScores(double test1, double test2, double test3) {
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)/3;

return testScores;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Bob huginstien · April 20, 2015
Thank you for the explanation! 
+2 Sharon Fabin · April 18, 2015
Hi, i copied you code and made some tweaks to it, try to see what i changed:


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


double calcAverage(double score1 = 0.0, double score2 = 0.0, double score3 = 0.0);
void GetTestScores();
void DisplayAverage(double average);
double score1, score2, score3;

int main() {
GetTestScores();
DisplayAverage(calcAverage(score1, score2, score3));
return 0;
}

void GetTestScores() {
cout << "First Test: ";
cin >> score1;
cout << "Second Test: ";
cin >> score3;
cout << "Third Test: ";
cin >> score3;
}

void DisplayAverage(double average){
cout << fixed << setprecision(1);
cout << "Average Score is: " << average << endl;
}

double calcAverage(double score1, double score2, double score3){
return (score1 + score2 + score3) / 3;
}


first of all, you didn't declare "void getTestScores" before the main.
Next, if you have an outter method (function) that is going to change the value of variables that you're going to use in your
main method, you have to declare global variables instead of local ones.
In the method "GetTestScores" all you have to do is to get input from user and assign it to 3 global variables, this method
doesn't return anything because it is a void one.
Next, you didnt make any metod called "calcAverage" or "DisplayAverage" as you're asked to.
you should make them because you're asked to as you wrote in your description.
And for last, you use "Get Scores" and "calcAverage" methods in your main method to calculate the average and output 
it using the "DisplayAverage" method in your main method.

I hope answered your question.
0 Bob huginstien · April 15, 2015
Please and thank you !
  • 1

C++

107,334 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator