6 Replies - 2227 Views - Last Post: 19 October 2009 - 10:11 AM Rate Topic: -----

#1 mgaines12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 13-October 09

Average Test Scores

Posted 19 October 2009 - 09:14 AM

Write a program that calculates the average of three test scores. The program must contain 3 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 3 times). The main() function then should call the calcAverage() function to calculate and return the average of the 3 test scores. When the calcAverage() function has completed its task, the main() function should display the average on the screen.

This is what I have but I cannot understand it for the life of me, can anyone tell me whats wrong?:


#include <iostream>

using std::cout;
using std::cin;
using std::endl;

//function prototype
double calcAverage (double);	
double getTestScore ();
using namespace std;


int main()
{
//declare variables
// change all 3 int scores to      double score = 0.0  1 time only;

double score1 = 0.0;		
double score2 = 0.0;
double score3 = 0.0;
double average = 0.0;

//get input items		
// do    for (x = 1; x<=3; x+=1)

cout << "First test score: ";					

cin >> score1;										
cout << "Second test score: ";	
					
cin >> score2;										
cout << "Third test score: ";		

cin >> score3;						

//call function to calculate payments
average = calcAverage (Accumulator);	
cout << "Average: " << average << endl;

return 0;
} //end of main function

//function definitions
double calcAverage (double Accumulator)
{
double avg = 0.0;
avg = Accumulator/3;
return avg;
} //end of calcAverage function 

 // called 3 times by for statement
double getTestScore() 
{
	
cout << endl;

return score;
}  // end of getTestScore function


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 19 October 2009 - 09:36 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Average Test Scores

#2 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: Average Test Scores

Posted 19 October 2009 - 09:16 AM

please put your code between code tags
Was This Post Helpful? 0
  • +
  • -

#3 mgaines12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 13-October 09

Re: Average Test Scores

Posted 19 October 2009 - 09:29 AM

I tried to fix the tags sorry I'm really new to this stuff. My proff said it just needs a few small tweaks but I cannot get it to compile
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Average Test Scores

Posted 19 October 2009 - 09:37 AM

You've given us your assignment and your code (next time :code: ), but you've not told us what is the problem.
Was This Post Helpful? 0
  • +
  • -

#5 mgaines12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 13-October 09

Re: Average Test Scores

Posted 19 October 2009 - 09:55 AM

Okay, heres the code and the errors I'm getting are below it if anyone can help me fix it to where I can get it to compile I'd be very appreciative:


#include <iostream>

using std::cout;
using std::cin;
using std::endl;

//function prototype
double calcAverage (double);	
double getTestScore ();
using namespace std;


int main()
{
//declare variables
// change all 3 int scores to      double score = 0.0  1 time only;

double score1 = 0.0;		
double score2 = 0.0;
double score3 = 0.0;
double average = 0.0;

//get input items		
// do    for (x = 1; x<=3; x+=1)

cout << "First test score: ";					

cin >> score1;										
cout << "Second test score: ";	
					
cin >> score2;										
cout << "Third test score: ";		

cin >> score3;						

//call function to calculate payments
average = calcAverage (Accumulator);	
cout << "Average: " << average << endl;

return 0;
} //end of main function

//function definitions
double calcAverage (double Accumulator)
{
double avg = 0.0;
avg = Accumulator/3;
return avg;
} //end of calcAverage function 

 // called 3 times by for statement
double getTestScore() 
{
	
cout << endl;

return score;
}  // end of getTestScore function



Errors:
c:\users\matt\documents\visual studio 2005\projects\chapt 9\chapt 9\chapt 9.cpp(33) : error C2144: syntax error : 'double' should be preceded by ')'
c:\users\matt\documents\visual studio 2005\projects\chapt 9\chapt 9\chapt 9.cpp(33) : error C2660: 'calcAverage' : function does not take 0 arguments
c:\users\matt\documents\visual studio 2005\projects\chapt 9\chapt 9\chapt 9.cpp(33) : error C2059: syntax error : ')'
c:\users\matt\documents\visual studio 2005\projects\chapt 9\chapt 9\chapt 9.cpp(53) : error C2062: type 'double' unexpected
Was This Post Helpful? 0
  • +
  • -

#6 aaa111  Icon User is offline

  • D.I.C Regular

Reputation: 88
  • View blog
  • Posts: 284
  • Joined: 21-February 07

Re: Average Test Scores

Posted 19 October 2009 - 10:08 AM

You should declare a variable before it can be used.Here you have not declare the Accumulator variable beforehand:
average = calcAverage (Accumulator); 

Another mistake is that you are returning a variable which also has not been declared:
double getTestScore() 
{
		
cout << endl;

return score; <-
}

This post has been edited by aaa111: 19 October 2009 - 10:09 AM

Was This Post Helpful? 0
  • +
  • -

#7 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 120
  • View blog
  • Posts: 710
  • Joined: 15-October 09

Re: Average Test Scores

Posted 19 October 2009 - 10:11 AM

View Postmgaines12, on 19 Oct, 2009 - 08:55 AM, said:

//call function to calculate payments
average = calcAverage (Accumulator);	
cout << "Average: " << average << endl;



Here, Accumulator appears for the first time, and it is not declared, nor initialized. Presumably, Accumulator will... accumulate score1 score2 and score3

Quote

double getTestScore() 
{
	
cout << endl;

return score;
}  // end of getTestScore function


Here score is not defined either, and not set to anything. Actually, it's not clear what this function does.

This post has been edited by EdwinNameless: 19 October 2009 - 10:12 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1