Reputation: 19
Good evening everyone, In attempting to write my grade code for class I seem to have come errors... Namely the operator after the && gives the error (expected an expression) and that the else statements give an error saying there is no if statement. Anyone care to help?
#include <iostream>
using namespace std;
int main()
{
double point;
cout << "Enter your grade point." << endl;
cin >> point;
if (point <= 100 && >= 90) {
cout << "Congratulations! You got an A" << endl;
}
else if (point >= 80 && < 90) {
cout << "Good Job, you got a B" << endl;
}
else if (point >= 70 && < 80) {
cout << "You got a C, at least it counts." << endl;
}
else if (point >= 60 && < 70)
{
cout << "You got a D... should have tried harder" << endl;
}
else if (point >= 0 && < 60)
{
cout << "You got an E. What happened?!?" << endl;
}
else if (point < 0 || >100)
{
cout << "Invalid input" << endl;
}
system("pause");
return 0;
}
Upvotes: 1
Views: 74
Reputation: 13434
Since I already explained what's wrong in the comment, I figured out that it might be helpful to write a full answer with additional hints.
Taking a second look at your problem: The expression if(point <= 100 && >= 90)
is incorrect since the if
statement expects a bool
expression. Logical operator &&
determinates whether or not the left and right bool
expressions are true
and returns so if both indeed are. Pay attention to what you just read. Both expressions means that there is a need for two of them. The first one, being point <= 100
satisfies the requirements. However, the second one you provided is >= 90
. This is not a valid expression, since you are expected to provide an indepented one. What you probably have in mind is check if 100 <= point <= 90. You have to separate it into two, independent expressions - if (point <= 100 && point >= 90) { // your code }
Additionally, I encourage you to read why using namespace std;
is wrong.
Upvotes: 3