I'm trying to build a simple program that asks for a grade whether it is numerical or general weighted average e.g. 75, 1.5 respectively. And when the user input a non numerical number a stated in the if condition, it prints error as stated also in the else condition. The problem is when I enter a 3-digit,4 , 5 digit number and so on, I get an error that is supposed to be Grade is not within the scope as stated in the nested if (else inside the if condition). Also the same thing happens when I enter 0. But the good thing is, when I enter a negative number or integer, it properly works well. Can I ask what is the problem with my condition? (Tnx in advance)
#include <iostream>
using namespace std;
int main ()
{
double grade;
cout<<"Enter Grade or GWA: ";
cin>>grade;
if (grade!=grade>='a'&&grade<='z'||grade!=grade>='A'&&grade<='Z')
/*The first If condition states that the user will get an error if
input a non-numerical integer or number.*/
{
if (grade<=5&&grade>=1)
{
if (grade>2.5)
cout<<"Failed"<<endl;
else
cout<<"Passed"<<endl;
}
else if (grade<75&&grade>=0)
cout << "Failed" << endl;
else if (grade>=75&&grade<=100)
cout << "Passed" << endl;
else
cout<<"Grade is not within the scope!"<<endl;
}
else
cout<<"Error!"<<endl;
cin.get();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire