I have some problem with the loop I trying to do. My code will prompt user for the value 1, 2 to do something, and 3 to exit. When I try to add the check for the input if it is not integer the loop will just loop non stop. I wonder is my if( !input) is wrongly used here? Can someone guide me? thanks.
do
{
printf ("Input no\n");
scanf ("%d", &input);
if (input)
{
if ( input == 1)
{
printf ("do wat u wan if is 1\n");
}
if ( input == 2)
{
printf ("do wat u wan if is 2\n");
}
}
else if (!input)
{
printf("error\n");
}
}
while(input !=3 );
if ( input == 3)
{
printf ("exiting\n");
}