help urgent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • confusedandinsane
    New Member
    • Sep 2006
    • 6

    help urgent

    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
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    [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

    Code:
    if (grade>= 90)
    {
      letter_grade = "A";
      totalA++;
    }
    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

    Code:
    if (grade>= 90)
    {
      letter_grade = 'A';
    }
    else if (grade>= 80)
    {
      letter_grade = 'B';
    }
    else
    {
      letter_grade = 'F';
    }

    Comment

    • confusedandinsane
      New Member
      • Sep 2006
      • 6

      #3
      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

      Code:
      if (grade>= 90)
      {
        letter_grade = "A";
        totalA++;
      }
      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

      Code:
      if (grade>= 90)
      {
        letter_grade = 'A';
      }
      else if (grade>= 80)
      {
        letter_grade = 'B';
      }
      else
      {
        letter_grade = 'F';
      }
      [/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 .

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        What you had in your original post looks about right to me

        Comment

        Working...