#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
char fallen;
int user;
int result;
cout << "Enter a letter \n";
cout << "\n";
cin >> fallen;
cout<< "\n";
cout<< "\n";
switch (fallen)
{
case'A':
case'a':
cout<< "You are amazing. \n";
cout << "\n";
cout << "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user >= 90 <= 100)
{
result = (100 - user);
cout<< "\n";
cout<< " You are " << result << " points away from a perfect score. \n";
cout<< "\n";
}
if (user >= 101 <= 89)
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
break;
case'B':
case'b':
cout<< "You did good. \n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user >= 89 <= 80)
{
result = (90 - user);
cout<< "\n";
cout<< " You are " << result << " points away from an 'A' score. \n";
cout<< "\n";
}
if (user >= 90 <= 79)
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
break;
case'C':
case'c':
cout<< "You did ok, but there is room for improvement. \n";
cout << "What exact percent did you get on your test? \n";
cin.ignore ();
cout << "\n";
cin >> user;
if (user >= 79 <= 70)
{
result = (80 - user);
cout<< "\n";
cout<< " You are " << result << " points away from a perfect score. \n";
cout<< "\n";
}
if (user >= 80 <= 69)
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
break;
case'D':
case'd':
cout<< "You have to do better, you have brought shame to your family. \n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user >= 69 <= 60)
{
result = (70 - user);
cout<< "\n";
cout<< " You are " << result << " points away from a perfect score. \n";
cout<< "\n";
}
if (user >= 70 <= 59)
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
break;
case'F':
case'f':
cout<< "You are a failure and a complete fool. \n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user >= 59 <= 50)
{
result = (60 - user);
cout<< "\n";
cout<< " You are " << result << " points away from a perfect score. \n";
cout<< "\n";
}
if (user >= 60 <= 49)
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
break;
default:
cout<< "You freakin idiot, thats not an answer. \n";
cout<< "\n";
}
cin.ignore ();
cin.ignore ();
cin.get ();
cin.get ();
system("pause");
}
}
}
}
}
}
Are you honestly saying this code compiles? There should be quite a few compiling errors...
a) I have no idea where all those }'s are coming from in the last few lines.
b) Your if's are wrong. You can't double up on arguments like that. The proper way is "if (y > x && y < z)".
c) Your main isn't returning a value.
d) There is a whole Sticky on how to keep your console open at the end. Easiest way? Add this as your final two lines of main() (only followed by "return 0;")
1 2
int i;
cin >> i;
e) Some of your if's don't close ('}'). Check 38, and many others.
@Gaminic: You're correct about b, but it does compile; when I tried it it just gave me a warning. Also, I'm pretty sure you don't need to return a value in int main() anymore. An easier way to keep the console open is cin.getline(); instead of creating a variable. Please correct me if I'm wrong about any of that.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
char fallen;
int user;
int result;
cout << "Enter a letter \n";
cout << "\n";
cin >> fallen;
cout<< "\n";
cout<< "\n";
switch (fallen)
{
case'A':
case'a':
cout<< "You are amazing. \n";
cout << "\n";
cout << "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin >> user;
if (user >= 90 && user <= 100)
{
result = (100 - user);
cout<< "\n";
cout<< " You are " << result << " points away from a perfect score. \n";
cout<< "\n";
}
elseif (user >= 101 && user <= 89)
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
case'B':
case'b':
cout<< "You did good. \n";
cout<< "\n";
cout<< "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user >= 89 && user <= 80)
{
result = (90 - user);
cout<< "\n";
cout<< " You were " << result << " points away from an 'A'. \n";
cout<< "\n";
}
else (user >= 90 && user <= 79);
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
case'C':
case'c':
cout<< "You did ok, but there is room for improvement. \n";
cout<< "\n";
cout<< "\n";
cout << "What exact percent did you get on your test? \n";
cin.ignore ();
cout << "\n";
cin >> user;
if (user >= 79 && user <= 70)
{
result = (80 - user);
cout<< "\n";
cout<< " You were " << result << " points away from a 'B'. \n";
cout<< "\n";
}
elseif (user >= 80 && user <= 69)
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
case'D':
case'd':
cout<< "You have to do better, you have brought shame to your family. \n";
cout<< "\n";
cout<< "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user >= 69 && user <= 60)
{
result = (70 - user);
cout<< "\n";
cout<< " You were " << result << " points away from a 'C'. \n";
cout<< "\n";
}
else (user >= 70 && user <= 59);
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
case'F':
case'f':
cout<< "You are a failure and a complete fool. \n";
cout<< "\n";
cout<< "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user >= 59 && user <= 50)
{
result = (60 - user);
cout<< "\n";
cout<< " You were " << result << " points away from a 'D'. \n";
cout<< "\n";
}
elseif (user >= 60 && user <= 49)
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
default:
cout<< "You freakin idiot, thats not an answer. \n";
cout<< "\n";
}
cin.ignore ();
cin.ignore ();
cin.get ();
cin.get ();
system("pause");
}
The conditions in your if statements will always be false. No number is less than or equal to a number and greater than or equal to a bigger number. Switch the logical operators.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
char fallen;
int user;
int result;
cout << "Enter a letter \n";
cout << "\n";
cin >> fallen;
cout<< "\n";
cout<< "\n";
switch (fallen)
{
case'A':
case'a':
cout<< "You are amazing. \n";
cout << "\n";
cout << "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin >> user;
if (user >= 90 && user <= 100)
{
result = (100 - user);
cout<< "\n";
cout<< " You are " << result << " points away from a perfect score. \n";
cout<< "\n";
}
else
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
case'B':
case'b':
cout<< "You did good. \n";
cout<< "\n";
cout<< "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user <= 89 && user >= 80)
{
result = (90 - user);
cout<< "\n";
cout<< " You were " << result << " points away from an 'A'. \n";
cout<< "\n";
}
else
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
case'C':
case'c':
cout<< "You did ok, but there is room for improvement. \n";
cout<< "\n";
cout<< "\n";
cout << "What exact percent did you get on your test? \n";
cin.ignore ();
cout << "\n";
cin >> user;
if (user <= 79 && user >= 70)
{
result = (80 - user);
cout<< "\n";
cout<< " You were " << result << " points away from a 'B'. \n";
cout<< "\n";
}
else
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
case'D':
case'd':
cout<< "You have to do better, you have brought shame to your family. \n";
cout<< "\n";
cout<< "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user <= 69 && user >= 60)
{
result = (70 - user);
cout<< "\n";
cout<< " You were " << result << " points away from a 'C'. \n";
cout<< "\n";
}
else
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
case'F':
case'f':
cout<< "You are a failure and a complete fool. \n";
cout<< "\n";
cout<< "\n";
cout << "What exact percent did you get on your test? \n";
cout << "\n";
cin.ignore ();
cin >> user;
if (user <= 59 && user >= 50)
{
result = (60 - user);
cout<< "\n";
cout<< " You were " << result << " points away from a 'D'. \n";
cout<< "\n";
}
else
{
cout<< "\n";
cout<< "I' am sorry that is not with in your grade range. \n";
cout<< "\n";
}
break;
default:
cout<< "You freakin idiot, thats not an answer. \n";
cout<< "\n";
}
cin.ignore ();
cin.ignore ();
cin.get ();
cin.get ();
system("pause");
}
changed else ifs to elses... changed your grade range