943,935 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1252
  • C++ RSS
May 8th, 2007
0

Help with a program

Expand Post »
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!

  1. #include <iostream>
  2. using namespace std;
  3. int get_letter grade(int);
  4. int main()
  5. {
  6. int numeric_grade,
  7. letter_grade;
  8.  
  9. cout << " Enter the exam grade: " ;
  10. cin >> numeric_grade;
  11. cout endl;
  12. letter_grade = get_letter grade(numeric_grade);
  13. cout <<endl;
  14. cout <<" The letter grade is "<< letter_grade << endl;
  15. cout << endl;
  16.  
  17. return 0;
  18. }
  19. int get_letter grade ( numeric_grade)
  20.  
  21. {
  22. ((10- (grade/10)) + 64)
  23. return;
  24.  
  25. }
Last edited by WaltP; May 10th, 2007 at 1:10 am. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tony71 is offline Offline
3 posts
since May 2007
May 8th, 2007
2

Re: Help with a program

Your get_letter grade function has a space in its name, and the implementation doesn't return anything.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
May 8th, 2007
0

Re: Help with a program

>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 keyword before the expression.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
May 9th, 2007
0

Re: Help with a program

I did the changes but still having issues.
:-(
  1. #include <iostream>
  2. using namespace std;
  3. int Exam_Grade(int);
  4. int main()
  5. {
  6. int numeric_grade;
  7. char letter_grade;
  8. cout << " Enter the exam grade: ";
  9. cin >> numeric_grade;
  10. cout endl;
  11. letter_grade= Exam_Grade(numeric_grade);
  12. cout<<endl;
  13. cout <<" The letter grade is "<< letter_grade << endl;
  14. cout << endl;
  15. return 0;
  16. }
  17. int Exam_Grade(int numeric)
  18. {
  19. double grade;
  20. grade= ((10- (grade/10)) + 64);
  21.  
  22.  
  23. return grade;
  24. }
Last edited by WaltP; May 10th, 2007 at 1:11 am. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tony71 is offline Offline
3 posts
since May 2007
May 9th, 2007
0

Re: Help with a program

>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".
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
May 9th, 2007
0

Re: Help with a program

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

>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...
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 9th, 2007
0

Re: Help with a program

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!
Reputation Points: 29
Solved Threads: 2
Newbie Poster
iTaChi is offline Offline
21 posts
since Mar 2007
May 10th, 2007
0

Re: Help with a program

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

And I changed grade to numeric and that worked.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tony71 is offline Offline
3 posts
since May 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ help (string class)
Next Thread in C++ Forum Timeline: problem with system() function...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC