I have a tough time trying to break what's in here:

#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
int main ()

{
float grade;
string name;

cout << " Please input your name: " << endl;
getline(cin,name);
cout << " Please input your grade: " << endl;
cin >> grade; 

if ( grade >= 96.30 && grade <= 100)
{ 
cout << " 1.00 " << endl;
}
else if (grade >= 92.40 && grade <= 96.29)
{
cout << "1.25" << endl;
}
else if (grade >= 88.50 && grade <= 92.39)
{
cout << "1.50" << endl;

}
else if ( grade >= 84.60 && grade <= 88.49)
{
cout << " 1.75 " << endl;
}
else if (grade >= 80.70 && grade <= 84.59)
{
cout << " 2.00 " << endl;

}
else if (grade >= 76.80 && grade <= 80.69)
{
cout << " 2.25 " << endl;
}
else if (grade >= 72.90 && grade <= 76.79)
{
cout << " 2.50 " << endl;
}
else if (grade >= 68.90 && grade <= 72.89)
{
cout << " 2.75 " << endl;
}
else if (grade >= 65.00 && grade <= 68.89)
{
cout << " 3.00 " << endl;
}
else if ( grade = 0.00 && grade <= 64.99)
{
cout << " 5.00 " << endl;
}

cout << name << "your final grade is " << grade;

}

Somehow when i enter a lower grade like 23 or 46, it shows up "0" rather than having a grade of "5.00"
Can someone help me?

Recommended Answers

All 2 Replies

Line 54:

else if ( grade = 0.00 && grade <= 64.99)

The dreaded = instead of == bug. = is the assignment operator. == is the comparison operator. I'm not exactly sure what you want in that line, but I am extremely confident you don't want the assignment operator. Perhaps you wanted >= like all the others...

else if ( grade >= 0.00 && grade <= 64.99)

or perhaps leave that first part out and do this:

else if (grade <= 64.99)

or even this...

else

Am I assuming correctly that grade should range from 0 to 100, inclusive?

One suggestion is that you always put the numeric value on the left side of the expression. That way, if you accidentally use '=' instead of '==', the compiler will complain. IE:
else if (0.00 = grade && 64.99 >= grade)
This will generate a compiler error for the first term. Also, I think you want to use an 'OR' instead of 'AND' as in
else if (0.00 == grade || 64.99 >= grade) because the grade cannot be both 0.00 and <= 64.99 at the same time (unless it is actually 0.00). Anyway, you really need to re-analyze your code. I don't think it is working the way you want.

commented: Ah yes. The Yoda conditional. +14
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.