By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,369 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,369 IT Pros & Developers. It's quick & easy.

help urgent

P: 6
how do you use the if function and how would one declare its values, example for a grading system for school

#include (iostream)

using namespace std;

char letter-grade;


cout<<"enter grade";
cin>>grade;

if (grade>= 90)
letter -grade = "A";

what am I missing, and how do I close the statement once it reaches to F
Sep 20 '06 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
[code]
if (grade>= 90)
letter_grade = 'A';
[/codeif is a statement NOT a function

What you have here is a complete if statement, it needs no closing, note I have corrected your string constant to a character constant and made your variable name valid.

If you want to execute more than 1 line of code when the condition is true then put in braces and have an if block

Expand|Select|Wrap|Line Numbers
  1. if (grade>= 90)
  2. {
  3.   letter_grade = "A";
  4.   totalA++;
  5. }
  6.  
You did not show code extending to 'F' so it is a little hard to know what you mean however are you talking about if - else if - else

Expand|Select|Wrap|Line Numbers
  1. if (grade>= 90)
  2. {
  3.   letter_grade = 'A';
  4. }
  5. else if (grade>= 80)
  6. {
  7.   letter_grade = 'B';
  8. }
  9. else
  10. {
  11.   letter_grade = 'F';
  12. }
  13.  
Sep 20 '06 #2

P: 6
QUOTE=Banfa][code]
if (grade>= 90)
letter_grade = 'A';
[/codeif is a statement NOT a function

What you have here is a complete if statement, it needs no closing, note I have corrected your string constant to a character constant and made your variable name valid.

If you want to execute more than 1 line of code when the condition is true then put in braces and have an if block

Expand|Select|Wrap|Line Numbers
  1. if (grade>= 90)
  2. {
  3.   letter_grade = "A";
  4.   totalA++;
  5. }
  6.  
You did not show code extending to 'F' so it is a little hard to know what you mean however are you talking about if - else if - else

Expand|Select|Wrap|Line Numbers
  1. if (grade>= 90)
  2. {
  3.   letter_grade = 'A';
  4. }
  5. else if (grade>= 80)
  6. {
  7.   letter_grade = 'B';
  8. }
  9. else
  10. {
  11.   letter_grade = 'F';
  12. }
  13.  
[/quote]


Thank you for you taking time out to guide me in the right direction. I am using Visual Studio 6.0, and I was unclear to write the statement so that it is recognize, you hit on the nose with the rest of the code you provided. I just do not know what shoud I start with before letter grade or IF .
Sep 20 '06 #3

Banfa
Expert Mod 5K+
P: 8,916
What you had in your original post looks about right to me
Sep 21 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.