I am VERY novice and working on a school project in C++. I'm not sure where I've gone wrong here in this code. Any advice on why this is not working would be appreciated. Please, pretend like you are talking to someone who knows very little about programming so far. :)

   #include <iostream>

 using namespace std ;

 int main() 
{
    float score ;
    char grade ;   

     // read in total score 

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

    if (score >= 85) 
        {
            grade = 'A' ;
    }


    else (score >= 75) 
        {
            grade = 'B' ;
    }

    else (score >= 65)
        {
            grade = 'C' ;
    }

    else (score >= 55)
        {
            grade = 'D' ;
    }

    else {
            grade = 'F' ;
        }

      // display the result 

     cout << endl ; 
     cout << "Your grade for CMSC 101 is: " << grade << endl ; 

     return (0); // terminate with success 
} 

Welcome to DaniWeb! To help us help you, here are some tips:

1) Use code tags (I see you put brackets around the code, but you need to use code goes here [/code ] (but without the space)

2) Please tell us what the program is supposed to do. We can't know what is going wrong if we don't know what the result is supposed to be. Show us a sample input (or see #3 below), the current output, and tell us the expected output.

3) I always suggest hardcoding values to make sure there is no problem with your user input. Once it works as you would expect with a hardcoded value, you can then test the user input.

Good luck,

David[code ]code goes here [/code ] (but without the space)

2) Please tell us what the program is supposed to do. We can't know what is going wrong if we don't know what the result is supposed to be. Show us a sample input (or see #3 below), the current output, and tell us the expected output.

3) I always suggest hardcoding values to make sure there is no problem with your user input. Once it works as you would expect with a hardcoded value, you can then test the user input.

Good luck,

David

Do you have to use if/else statements? A switch would better serve your needs. If you must use if/else, don't try to pass a condition to the else statement. 'else' will execute if the 'if' is false. So an if/else should look similar to

if(condition) {
    do this}
else {
    do that}

instead of the
if
else
else
else
what u need is
if
else if
else if
else

What bigwhiteegg said is correct, to demonstrate this I've added it into your code and hope this makes it very clear where your problem lies.

#include <iostream>

using namespace std ;

int main() 
{
float score ;
char grade ; 

// read in total score 

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

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 CMSC 101 is: " << grade << endl ; 

return (0); // terminate with success 
}

I am VERY novice and working on a school project in C++. I'm not sure where I've gone wrong here in this code. Any advice on why this is not working would be appreciated. Please, pretend like you are talking to someone who knows very little about programming so far. :)

 #include <iostream>

 using namespace std ;

 int main() 
{
    float score ;
    char grade ;   

     // read in total score 

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

    if (score >= 85) 
        {
            grade = 'A' ;
    }


    else (score >= 75) 
        {
            grade = 'B' ;
    }

    else (score >= 65)
        {
            grade = 'C' ;
    }

    else (score >= 55)
        {
            grade = 'D' ;
    }

    else {
            grade = 'F' ;
        }

      // display the result 

     cout << endl ; 
     cout << "Your grade for CMSC 101 is: " << grade << endl ; 

     return (0); // terminate with success 
} 

end quote.

You don't write else else. You should change all the else( ) to ifs

Switches will not work here because it is not just a plain value like 85. The program also has < signs.

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.