0

I'm having a problem with the program i did.
The problem is ;

It says that the conversion ( for the grade part , the ones with '+' and '-') may lose it's significant digit.. Does it mean that i can't use the plus symbol or the minus symbol ?? or i need to declare how many characters for grade ? ( char grade [5] ? )

How many nested if's can i do?

And another one is , it says i misplaced the last else .. Um , does it mean that the else if above it needs a curly bracket? Or am I entirely wrong?

I'm using Borland C++ and I'm sorry that it's messy. I started learning computer programming a month ago ; a total newbie. So I'm sorry again and thank you very much.

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

int main()
{  int score ;
      char grade ;

    cout<<"Hello. Please insert your test score. Thank you."<<endl ;
    cin>>score ;

   if ( score >= 0 && score <= 100 )
   {    if( score >= 75 && score <= 100 )

        {if (score >= 90 )
                    grade = 'A+' ;
        else if ( score >= 80 && score < 90 )
                        grade = 'A' ;
                else if ( score >= 75 && score < 80 )
                                grade = 'A-' ;

          cout<<"Congratulations. Your grade is "<<grade ;
        }

        else if ( score >= 60 && score < 75 )
          { if ( score >=70 && score < 75 )
                        grade = 'B+' ;
            else if (score >=65 && score <70)
                                grade = 'B' ;
                else if (score >= 60 && score < 65 )
                                    grade = 'B-' ;

         cout<<"Good. Your grade is "<<grade ;
          }

      else if ( score >= 50 && score , 60 )
          { if (score >=55 && score < 60 )
                        grade = 'C+' ;
            else if (score >= 50 && score < 55 )
                                grade = 'C' ;

            cout<<"Pass. Your grade is "<<grade ;
      }

      else if ( score >= 40 && score < 50 )
           { if (score >=47 && score < 50 )
                        grade = 'C-' ;
            else if (score >= 44 && score < 47 )
                                grade = 'D+' ;
                else if (score >= 40 && score < 44 )
                                    grade = 'D' ;

         cout<<"Sorry, you failed. Your grade is "<<grade ;

       }

       else if (score >= 30 && score <40 )
                grade = 'E' ;
                cout<<"Sorry, your result is poor. Your grade is "<<grade ;

       else if (score >= 0 && score < 30 )
                    grade = 'F' ;
                cout<<" Sorry , your result is very poor. Your grade is "<<grade<<" . Please try again next semester!" ;

      }

      else
        cout<<"Invalid score. Please try again ! " ;

   getch();
   return 0 ;
}
3
Contributors
4
Replies
23
Views
3 Weeks
Discussion Span
Last Post by Nrsrh
1

you could make your logic a lot less complicated by something like

if (score > 100)
    \\invalid
else if (score >= 90)
    \\A+
else if (score >= 80)
    \\A
else if (score >= 75)
    \\A-

etc.

You should also pick one of the more widely accepted methods of using brace brackets. For example

if (condition) {
    statement;
    statement;
}

or

if (condition)
{
    statement;
    statement;
}

but not

if (condition)
{   statement;
    statement;
}

If you'd done that your bracket mismatch problem would have been immediately obvious.

1

PS: Most good code editors have a hotkey where you place the cursor over a bracket and the hotkey toggles to/from the matching bracket.

0

oh i see . thank you ddanbe , i tried changing it and it works :D

Reverend Jim , thank you :) i'll try using the first method later on. Thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.