1

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;
}
  • 12
    `if (point <= 100 && >= 90)` is wrong. `&&` expects 2 boolean expressions and `>= 90` is not an expression. What you want is `if (point <= 100 && point >= 90)`. Apply this logic to all the cases – Fureeish Sep 06 '17 at 22:31
  • Welcome to Stack Overflow! To help people answer your question, you'll need to be more specific about the error. Please [edit] your post to incorporate the exact errors you get from your [mcve] (preferably using copy+paste to avoid transcription errors). – Toby Speight Sep 07 '17 at 14:07

1 Answers1

3

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.

Fureeish
  • 12,533
  • 4
  • 32
  • 62
  • careful not to spend too much time correcting people for unrelated things when posting an [mcve]. The point of the example is to demonstrate the issue. Stylistic shortcuts are often beneficial for this when they make the core issue more clear and take away from things that would otherwise distract from it. – xaxxon Sep 06 '17 at 22:46