+ 1
Can someone help me with a simple C request?
I'm trying to make a simple "short a, b;" code where you enter two numbers and the program tells you what you entered. Quite simple, but I can't make a "fail safe". I want the program to make a "printf: you don't respect the rules" if someone entered characters instead of numbers. I didn't succeed with if / else and I'm looking for help here.
7 ответов
+ 4
Best maybe then to take the input as string and convert it to real numbers later.
Then you can do tests based on the ASCII order of letters (google that), for example:
for(int i=o; my_string[i]; ++i)
if(my_string[i]<'0' || my_string[i]>'9')
printf("Only numbers please!") ;
+ 3
Vadean Alex there is no short for floating point values.... There are only three ways for decalaring floating point value i.e., float,double and long double
+ 2
Ah! I see. Thank you very much 💞
+ 2
It worked! Thanks man. Feeling quite confident that I managed to make a simple calculator. Can't wait to see what else I can create. Thank you all for your help.
+ 1
Martin Taylor, do you think you can give a small example of the code with your method? I tried it, but it doesn't work and I think it's because I'm working with float numbers, but not sure..