Originally Posted by
ferfy
Or i could just remove the exclamation mark
Yeah, that would make things easier. In that case, I would write the program like this:
Code:
#include <iostream>
int main()
{
std::cout << "Enter your grade %: ";
int grade;
std::cin >> grade;
if (grade <= 60)
{
std::cout << "You scored an F";
}
else if (grade <= 70)
{
std::cout << "You scored a D";
}
else if (grade <= 80)
{
std::cout << "You scored a C";
}
else if (grade <= 90)
{
std::cout << "You scored a B";
}
else
{
std::cout << "You scored an A";
}
if (grade > 60)
{
int last_digit = grade % 10;
if (last_digit > 0 && last_digit <= 3)
{
std::cout << '-';
}
else if (last_digit > 7 || last_digit == 0)
{
std::cout << '+';
}
}
std::cout << std::endl;
}
Notice the check for grade > 60. Without that, you'll be incorrectly printing the modifier for F.