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 ;
}

A char can only hold one character 'B+' are two chars, so use string instead.

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.

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.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.