Issue with too many arguments for function...

I'm getting an error on line 6 that reads "too many arguments to function 'char calcGrade'" and I'm not sure what I need to do to fix it. Any help would be appreciated.

Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;


double getScore();  // function prototype for the function getScore
char calcGrade ();  // add a function prototype for the function calcGrade here


int main()
{
    double score = 0.0;
    char grade = ' ';
    
    score = getScore();  // invoke the function getScore, store return value in score    
    grade = calcGrade(score);  // invoke the function calcGrade, pass score to it and store return value in grade
        

    cout << "Your letter grade is: " << grade << endl;
    system("pause");
    return 0;
}

double getScore()
{
    double myScore = 0.0;
    cout << "What is your test score? ";
    cin >> myScore;
    return myScore;
}

char calcGrade(double testScore)
{
    char letterGrade = ' ';
    if (testScore >= 90)
       letterGrade = 'A';
    else if (testScore >= 80)
       letterGrade = 'B';
    else if (testScore >= 70)
       letterGrade = 'C';
    else if (testScore >= 60)
       letterGrade = 'D';
    else
       letterGrade = 'F';

    return letterGrade;
}
you have forward declared char calcGrade (); and definition reads char calcGrade(double testScore) and you are calling it like grade = calcGrade(score);

Forward declaration and actual signature should be same.
I'm a bit confused, but I think you're saying I should change grade = calcGrade(score); to grade = calcGrade(testScore); but when I do that I get another error. Could you please expound? I'm very new to C++.
No, the prototype on line 6 needs to match the definition on line 31.
So change line 6 from this:
char calcGrade();
to this:
char calcGrade(double);

The name of the parameter is optional in the prototype, but the type is not.
Understood now... Thank you so much!!
Topic archived. No new replies allowed.