Need help asap!!! Please!!!

This is a discussion on Need help asap!!! Please!!! within the C Programming forums, part of the General Programming Boards category; I am writing a calculator code..
I am having issues with input validation.
I can't get in touch with my ...

Need help asap!!! Please!!!

I am writing a calculator code..
I am having issues with input validation.
I can't get in touch with my instructor as I am taking an online course.
I am in need of assistance....

I need to make it so my calculator forces the user to input integers for the menu options as well as for the calculations...
If they put a letter the program loops.
I need it to send an error to the user.
I have tried isdigit...but it isn't working.
i am new. my code is below:

I need to make it so my calculator forces the user to input integers for the menu options as well as for the calculations...
If they put a letter the program loops.
I need it to send an error to the user....

First off quzah did point you in the right direction. Secondly your program is looping if the user inputs anything besides 1-5 because you tell it to:

Code:

....
}while(option!=5);

Note in the discussion quzah posted it discussed using the return value from scanf(). Take a look at this simple example:

take a hint and get lost!!!...i have been reading..i'm new and a little confused...

Wow... you gotta work on that temper.

We are NOT going to hand you finished code... you won't learn a thing that way.

The answer to your problem lies in checking the return value of scanf() ... it returns the number of successful conversions (inputs). What do you think it returns if the user enters an unconvertable input?

Ok, so right here in your code is where you are taking user input and it could be where you could do the initial error check for your input:

Code:

scanf("%d",&option);
system("cls");

So, IF you wanted to check your input and then PRINT and error message how would you think you would go about it. I am sure that you ran the above sample code I posted and by now realize that scanf returns the number of successful conversions it performs.