Syntax Problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AZRebelCowgirl73
    New Member
    • Nov 2006
    • 47

    Syntax Problems

    I am trying to write a C++ program that tells the inputter what their letter grade is after they input their number grade I cant seem to make this program run. It is of the form if-then-else, and I dont want to make any changes to it expect for the if-then-else section and the variables if necessary?! Can someone help me!!!!!!!!


    int main()
    {
    int score;
    char grade;


    // read in total score

    cout << endl ;
    cout << "Enter total score (float, must be <= 100) : " ;
    cin >> score ;

    //compute grade

    if (score >= 85)
    {grade = 'A'};
    else if (score >= 75)
    {grade = 'B'};
    else if (score >= 65)
    {grade = 'C'};
    else if (score >= 55)
    {grade = 'D'};
    else {grade = 'F'};

    // display the result

    cout << endl ;
    cout << "Your grade for CMIS 102 is: " << grade << endl ;

    return (0); // terminate with success
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    none of you statements

    grade = '<SomeLetter>'

    have the required ; at the end of them.

    Instead you have put the ; outside the code block ({...})

    Laying out you code ina more orderly fasion would probably help prevent making the same mistake in the future.

    It is normal for the { to appear at the end of the if line or on the line below by it self.

    It is normal for the } to appear on a line by it self at the end of the code block.

    Comment

    • mohsin
      New Member
      • Nov 2006
      • 19

      #3
      HI
      well paranthieses of main function is missing '}'
      after when you return 0 to maion function

      Comment

      • mohsin
        New Member
        • Nov 2006
        • 19

        #4
        also
        in every case youy terminate the statement with } rather than ;
        you must have to use ; before } remove these error it will work
        inshaallah

        Comment

        • sivadhas2006
          New Member
          • Nov 2006
          • 142

          #5
          Originally posted by AZRebelCowgirl7 3
          I am trying to write a C++ program that tells the inputter what their letter grade is after they input their number grade I cant seem to make this program run. It is of the form if-then-else, and I dont want to make any changes to it expect for the if-then-else section and the variables if necessary?! Can someone help me!!!!!!!!


          int main()
          {
          int score;
          char grade;


          // read in total score

          cout << endl ;
          cout << "Enter total score (float, must be <= 100) : " ;
          cin >> score ;

          //compute grade

          if (score >= 85)
          {grade = 'A'};
          else if (score >= 75)
          {grade = 'B'};
          else if (score >= 65)
          {grade = 'C'};
          else if (score >= 55)
          {grade = 'D'};
          else {grade = 'F'};

          // display the result

          cout << endl ;
          cout << "Your grade for CMIS 102 is: " << grade << endl ;

          return (0); // terminate with success
          Hi,

          Try this...

          Code:
          #include <iostream>
          
          using namespace std;
          
          int main() 
          {
             int 
                nScore = 0;
             char 
                cGrade = '\0';
          
             // Get the total Score.
             cout << "\nEnter total Score (int, must be <= 100) : " ; 
             cin >> nScore ; 
          
             //Compute Grade
             if (nScore >= 85)
             {
                cGrade = 'A';
             }
             else if (nScore >= 75)
             {
                cGrade = 'B';
             }
             else if (nScore >= 65)
             {
                cGrade = 'C';
             }
             else if (nScore >= 55)
             {
                cGrade = 'D';
             }
             else 
             {
                cGrade = 'F';
             }
          
             // Display the Result.
             cout << endl ; 
             cout << "Your Grade for CMIS 102 is: " << cGrade << endl ; 
          
             return (0); // terminate with success
          }
          Regards,
          M.Sivadhas.

          Comment

          • AZRebelCowgirl73
            New Member
            • Nov 2006
            • 47

            #6
            thanks so much for the help! Trying to learn this alone has really become quite a task. Came across this site, by accident. Expect to be here alot! Thanks again for the help! I see that for the most part I had it, just need to space more and be more clear. Thanks

            Comment

            • thefarmer
              New Member
              • Nov 2006
              • 55

              #7
              try this also:

              #include <iostream.h>
              #include <conio.h>
              {

              clrscr ();
              // Enter the value of the grade
              cout << " The grade is: ";
              double grade;
              cin >> grade;

              if ( grade >= 85) cout << "A";
              else if (grade >= 75)
              cout << "B";
              else if (grade >= 65)
              cout << "C";
              else if (grade >= 55)
              cout << "D";
              else
              cout << "F- Failed";
              getch ();
              return 0;

              }

              regards,

              Comment

              Working...