how to do simple code for:
if(alphabet)
output ERROR
because char is int I cannot do like this:
if(sale >= 'a' && sale =< 'z')
because if my sale is 98 it will output error because b is 98.
I want number, not character. How?
That depends on how your incoming data is being read and stored.
The best way to read data from either keyboard or a file is
one line at a time using the "getline()" function, which gets data
from a stream and writes it to a std::string:
std::istream& std::getline ( std::istream& is, std::string& str );
If you're reading from keyboard, your stream is std::cin, so you might do
something like:
std::string InputString;
std::getline (std::cin, InputString);
To see whether the user entered alphabetic or numeric characters,
Look at the characters you get in your string using the character-type
functions in the <cctype> header (inherited from C), such as isalpha(),
islower(), isdigit(), etc. For example, if you're expecting only
positive integers, you can stipulate that unless every character passes
the isdigit() test, it's an error. Or, if you want to allow positive
or negative real numbers, also allow periods and minus signs.
Or, you can take a whole different approach and just use the atoi()
or atof() functions
std::string InputString;
double Number;
getline (std::cin, InputString);
Number = atof(InputString.c_str());
If the user enters garbage, Number will be zero. So if Number is zero,
then you know an error occured, unless zero is within your "allowable"
range of input numbers.
And there's other ways to do it as well. As usual, TIMTOWTDI.