954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with a program

HI guys,

I am taking C++ and I'm suppose to write this program where it asks the user to input a grade that they recieved in their exam . The grade is an interger from 0 to 100. Basicly the program should convert the numeric grade to a letter grade.

I have written the program and I only get two errors and can't figure it out and its driving me crazy. can someone please help me? Thanks!

#include <iostream>
using namespace std;
int get_letter grade(int);
int main()
{
 int numeric_grade,
        letter_grade;
 
 cout << " Enter the exam grade: " ;
    cin >> numeric_grade;
    cout endl;
 letter_grade = get_letter grade(numeric_grade);
  cout <<endl;
  cout <<" The letter grade is "<< letter_grade << endl;
  cout << endl;

  return 0;
}
int get_letter grade ( numeric_grade)
 
{
 ((10- (grade/10)) + 64)
return;

}
tony71
Newbie Poster
3 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Your get_letter grade function has a space in its name, and the implementation doesn't return anything.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

>int get_letter grade(int);
Can't have spaces in your function. And since you're calculating a letter grade, don't you think you had better return a letter instead of a number?

>int numeric_grade,
>letter_grade;
Likewise, you should make 'letter_grade' a char value, not an integer. It just makes sense.

>cout endl;
There's something special that needs to go between these...

>((10- (grade/10)) + 64)
>return;
Put the return keywordbefore the expression.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

I did the changes but still having issues.
:-(

#include <iostream>
using namespace std;
int Exam_Grade(int);
int main()
{
 int numeric_grade;
char letter_grade;
cout << " Enter the exam grade: ";
cin >> numeric_grade;
cout endl;
letter_grade= Exam_Grade(numeric_grade); 
cout<<endl;
cout <<" The letter grade is "<< letter_grade << endl;
cout << endl;
return 0;
}
int Exam_Grade(int numeric)
{
 double grade;
grade= ((10- (grade/10)) + 64);
 
 
 return grade;
}
tony71
Newbie Poster
3 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

>double grade;
>grade= ((10- (grade/10)) + 64);
If you never use a parameter of the function to calculate the grade, what makes you think it'll be calculated correctly?

>cout endl;
Again, I remind you: there is something that needs to go between "cout" and "endl".

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

>I did the changes but still having issues.
It would be nice if you told us what those issues were. :icon_rolleyes:

>cout endl;
That won't compile. You probably meant cout<<endl; .

>grade= ((10- (grade/10)) + 64);
grade doesn't have a predictable value but you use it in an expression...

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

in declaring and defining functions, you should know that there should be no whitespaces in the name,

also, you should assign the correct data type to a variable you declared, if you want it to function as a character, you should assign it as a char type.

good luck!

iTaChi
Newbie Poster
21 posts since Mar 2007
Reputation Points: 29
Solved Threads: 2
 

Thanks guys. I got it! One thing I was missing << like Joe mentioned. :-)

And I changed grade to numeric and that worked.

tony71
Newbie Poster
3 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You