I've searched all over the place, but I can't seem to figure out just what is going wrong. The 'if' and 'else' work normally, but the 'else ifs' seem to be ignored completely. Any help would be appreciated.
Exactly as above. Your code should be as follows. "grade ==" was incorrect, as you're only testing if grade is greater than a number and less than a number.
#include<iostream>
using namespace std;
int main() {
int grade;
cout<< "Enter student's percentage:\n";
cin>> grade ;
if ((grade>=0) && (grade<60))
{
cout<<"Student received an 'F'."<< endl;
}
else if ((grade>61) && (grade<70))
{
cout<< "Student recieved a 'D.'"<< endl;
}
else if ((grade>71) && (grade<80))
{
cout<< "Student recieved a 'C.'"<< endl;
}
else if((grade>81) && (grade<90))
{
cout<< "Student received a 'B.'"<< endl;
}
else if((grade>91) && (grade<=100))
{
cout<< "Atudent recieved an 'A.' Well done, student."<< endl;
}
else {cout<< "Please enter a value between 1 and 100."<< endl;
}
}
@ OP: Where did you learn that syntax from exactly? I've seen this from various other beginners and I have no clue how people get the idea that this is proper syntax for what they want.
Thank you all so very much, its a huge relief to know that it's a simple error.
@Computerquip: most online guides I've seen don't actually deal with boolean syntax as it relates to if statements (or maybe I managed to read over it several times). In either case, I was left more or less to my own devices when working out the correct syntax.