If statement error

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

    If statement error

    Hello:

    I am trying to compile this block of code but every time I try to do so I get the same error message. Missing syntax before cout<<"Enter grade\n";

    Can anyone tell me what is missing?
    Thank you


    #include <iostream>
    using namespace std;



    int main ()

    {

    char grade

    cout<<"Enter grade\n";
    cin>>grade;

    if (grade >90)
    cout<<"A";

    else

    if (grade >80)
    cout<<"B";

    return 0;

    }
  • vandalous
    New Member
    • Sep 2006
    • 7

    #2
    Originally posted by confusedandinsa ne
    Hello:

    I am trying to compile this block of code but every time I try to do so I get the same error message. Missing syntax before cout<<"Enter grade\n";

    Can anyone tell me what is missing?
    Thank you


    #include <iostream>
    using namespace std;



    int main ()

    {

    char grade

    cout<<"Enter grade\n";
    cin>>grade;

    if (grade >90)
    cout<<"A";

    else

    if (grade >80)
    cout<<"B";

    return 0;

    }

    hey there semi colon after grade

    Comment

    • confusedandinsane
      New Member
      • Sep 2006
      • 6

      #3
      Originally posted by vandalous
      hey there semi colon after grade
      Thank you for pointing that out to me, but now I finish writing the code out and I able to compile it, only the proble is that when I enter the number it does not give me the letter grade. I pasted the code below, can you see anything wrong here?

      #include <iostream>
      using namespace std;



      int main ()

      {

      char grade;

      cout<<"Enter grade";
      cin>>grade;

      if (grade >90)
      cout<<"A";

      else

      if (grade >80)
      cout<<"B";

      else

      if (grade >70)
      cout<<"C";

      else

      if (grade >60)
      cout<<"D";

      else

      if (grade >50)
      cout<<"F";



      return 0;

      }

      Comment

      • vandalous
        New Member
        • Sep 2006
        • 7

        #4
        Originally posted by confusedandinsa ne
        Hello:

        I am trying to compile this block of code but every time I try to do so I get the same error message. Missing syntax before cout<<"Enter grade\n";

        Can anyone tell me what is missing?
        Thank you


        #include <iostream>
        using namespace std;



        int main ()

        {

        char grade // ** semicolon missing here

        cout<<"Enter grade\n";
        cin>>grade;

        if (grade >90)
        cout<<"A";

        else

        if (grade >80)
        cout<<"B";

        return 0;

        }
        char grade // ** semicolon missing here

        Comment

        • vandalous
          New Member
          • Sep 2006
          • 7

          #5
          Originally posted by confusedandinsa ne
          Thank you for pointing that out to me, but now I finish writing the code out and I able to compile it, only the proble is that when I enter the number it does not give me the letter grade. I pasted the code below, can you see anything wrong here?

          #include <iostream>
          using namespace std;



          int main ()

          {

          char grade;

          cout<<"Enter grade";
          cin>>grade;

          if (grade >90)
          cout<<"A";

          else

          if (grade >80)
          cout<<"B";

          else

          if (grade >70)
          cout<<"C";

          else

          if (grade >60)
          cout<<"D";

          else

          if (grade >50)
          cout<<"F";



          return 0;

          }
          system("pause") ; // before return 0;

          it should work . it just depends on what number you put when you run the program
          Last edited by vandalous; Sep 28 '06, 04:26 PM. Reason: mistake

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            It is always worth having a else clause after and if else if ... even if it only outputs a debug message that you are expecting to get.

            If the grade is < 50 this program is not going to output anything.


            BTW for those scoring less than 50 was is the grade that is worst than an 'F'?

            Comment

            Working...