If else error

in the line | if (ifelse <= 65) && (ifelse > 50); | an error of "expected and expression" appears under && and an error of "expected a statement" appears in the line | else if (ifelse <= 50) && (ifelse >= 0) | under the else operator. Being that these errors show up no where else in my code I am lost as to their meaning and how to fix it. If someone could lend some insight that would be greatly appreciated. Thank you.



// Written by 10FEB2014
// This program calculates the average of seven grades entered based on different point scales.


#include <iostream>
using namespace std;

int main()

{

cout << "The following instructions are going to ask you to input";
cout << "\n seven grades starting with five lab grades then one project";
cout << "\n grade and then finally the grade recieved on the midterm";
cout << "\n \n labs will be out of 10 points, the project will be a letter";
cout << "\n grade of A B C D or F and the midterm grade is out of 70.";
cout << "\n \n After entering your grades the program will generate";
cout << "\n your calculated average." << endl;

float lab_1, lab_2, lab_3, lab_4, lab_5, Midterm, Project, Average;
float ifelse;


cout << "Enter your grade for lab 1 out of 10.";
cout << "lab 1 grade was ";
cin >> lab_1;
cout << "\n You entered " << lab_1 << " out of 10" << endl;

cout << "\n Enter your grade for lab 2 out of 10.";
cout << "lab 2 grade was ";
cin >> lab_2;
cout << "\n You entered " << lab_2 << " out of 10" << endl;

cout << "Enter your grade for lab 3 out of 10.";
cout << "lab 3 grade was ";
cin >> lab_3;
cout << "\n You entered " << lab_3 << " out of 10" << endl;

cout << "Enter your grade for lab 4 out of 10.";
cout << "lab 4 grade was ";
cin >> lab_4;
cout << "\n You entered " << lab_4 << " out of 10" << endl;

cout << "Enter your grade for lab 5 out of 10.";
cout << "lab 5 grade was ";
cin >> lab_5;
cout << "\n You entered " << lab_5 << " out of 10" << endl;

cout << "\n Enter your grade for the project of A=98, B=85, C=70, D=66, or F=50.";
cout << "The project grade was ";
cin >> Project;
cout << "\n You entered " << Project << endl;

cout << "\n Enter your grade for the mid term out of 70 possible points.";
cout << "\n Your mid term grade was ";
cin >> Midterm;
cout << "\n You entered " << Midterm << " out of 70" << endl;

ifelse = (Midterm/70)*100;

if (ifelse <= 65) && (ifelse > 50)
{
cout << "You have recived a D on the Midterm" << endl;
cout << "\nYou are in danger of failing this course. Please see your professor" << endl;
}
else if (ifelse <= 50) && (ifelse >= 0)
{
cout << "You have received and F on the Midterm." << endl;
cout << "You are failing this course. Your Advisor has been notified. \n Please see both your advisor and your professor." << endl;
}
else if (ifelse <= 100) && (ifelse >= 90)
{
cout << "You have received an A. CONGRADULATIONS!!" << endl;
}
else if (ifelse < 90) && (ifelse >= 80)
{
cout << "You have recieved a B. Great work." << endl;
}
else if (ifelse < 80) && (ifelse >= 65)
{
cout << "You have recieved a C. Work harder come time for the final." << endl;
}

Average = (((lab_1 + lab_2+lab_3+lab_4+lab_5)*10/5)*0.35)+(Project*0.35)+(((Midterm/70)*100)*0.35);

cout << "\n The average that you have received is a " << Average << " out of 100." << endl;

system ("pause");

return (0);

}
Last edited on
You have an extra semicolon:
if (ifelse <= 65) && (ifelse > 50); // <-- here
Thanks. I go rid of that, but now it recreates the errors I specified for all following else if operators. Any suggestions?
Oh yeah, I didn't even see this at first:
if ( (ifelse <= 65) && (ifelse > 50) ) // Missing parenthesis around the whole thing
and same with your other ones too.

EDIT: Actually, you can just rewrite it like this:
1
2
3
4
5
6
7
8
9
10
if (ifelse <= 50)
    // ...
else if (ifelse <= 65) // <= or just < ? I'm not sure about this one
    // ...
else if (ifelse < 80)
    // ...
else if (ifelse < 90)
    // ...
else
    // ... 

The reason being, if it doesn't pass the first if statement, then you know that ifelse is bigger than 50, so you don't have to check that again in your next if statements, and so on.
Last edited on
Fantastic! Thanks for the help. It's working now.
Topic archived. No new replies allowed.