# Average Test Scores

Page 1 of 1

## 6 Replies - 4605 Views - Last Post: 19 October 2009 - 10:11 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=132986&amp;s=a787a2fd9ab26836d57109c9ba475b0b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mgaines12

• New D.I.C Head

Reputation: 0
• 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 ***

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

• D.I.C Lover

Reputation: 139
• 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

### #3 mgaines12

• New D.I.C Head

Reputation: 0
• 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

• Saucy!

Reputation: 6219
• Posts: 23,965
• 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 ), but you've not told us what is the problem.

### #5 mgaines12

• New D.I.C Head

Reputation: 0
• 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

### #6 aaa111

• D.I.C Regular

Reputation: 88
• 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

### #7 EdwinNameless

Reputation: 123
• Posts: 720
• Joined: 15-October 09

## Re: Average Test Scores

Posted 19 October 2009 - 10:11 AM

mgaines12, 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