return value.

#include <iostream>
using namespace std;

void getScore(int& score);
int calculateGrade(int cScore);

int main()
{
int courseScore;


cout<<"Line 1: Based on the course score, \n"
<<" this program computes the"
<<"course grade."<<endl;

getScore(courseScore);
calculateGrade(courseScore);


cout<<"Line 7: Your grade for the course is "<<calculateGrade; <--HERE??

return 0;
}

void getScore(int& score)
{
cout<<"Line 4: Enter course score: ";
cin>>score;
cout<<endl<<"Line 6: Course score is "
<<score<<endl;
}
int calculateGrade(int cScore)
{
char Grade;

if(cScore>=90)
Grade='A';
else if(cScore>=80)
Grade='B';
else if(cScore>=70)
Grade='C';
else if(cScore>=60)
Grade='D';
else
Grade='F';

return Grade;
}


the program should cout 'grade' in main()...please fix this program.i mark the problem with " <--HERE??"...tq
Look at that line again. Then compare it with the one just above that.
int calculateGrade(intcScore) is wrong, if you are using return, a variable in main should get that value. It should be a void and cout the grade letter directly or make a char variable in main to get the value and output it.

1
2
3
4
5
char letter;
letter = calculateGrade(courseScore);


cout<<"Line 7: Your grade for the course is "<< letter << "\n\n"


and the function should be like this:
char calculateGrade(int cScore);
Last edited on
correct the calculateGrade(courseScore); This returns a value so i suggest is should be done this way.

either:

1)

int grade = calculateGrade(courseScore);
cout<<"Line 7: Your grade for the course is "<<grade;

2)

cout<<"Line 7: Your grade for the course is "<<calculateGrade(courseScore);
Topic archived. No new replies allowed.