#include <iostream>
//@author Will A. Training Exercise:Numerical to Letter Grade Converter
int main()
{
int grade = 0;
bool repeat = true;
std::cout<<"Grade Converter Created By Will A.\n";
while(repeat)
{
std::cout << "\nEnter Grade(numerical): ";
std::cin >> grade;
if((grade <=100)&&(grade >=90))
{
std::cout<<"Your Letter Grade:A\n";
}
elseif((grade <=89)&&(grade >=80))
{
std::cout<<"Your Letter Grade:B\n";
}
elseif((grade <=79)&&(grade >=70))
{
std::cout<<"Your Letter Grade:C\n";
}
elseif((grade <=69)&&(grade >=65))
{
std::cout<<"Your Letter Grade:D\n";
}
elseif((grade <=64)&&(grade >=0))
{
std::cout<<"Your Letter Grade:F\n";
}
else
{
std::cout<<"You did not enter a correct number\n";
}
}
}
Because grade is holding what you're typing in and grade is of type int.
A letter is just an ascii value, so grade is holding the ascii int value of the character you entered.
Lots of ways to fix it, you could get user input and then check if it's digits before changing it to an int. You could do that using ascii values, If val is a digit then int = val - '0'.
You could play around with stringstream also.
You could write your own function to check if every value in a string is a digit. Like with a for loop and a string iterator and the function isdigit.