I want to make sure that my user only enters a numbered response and if not then it goes back to asking the main question. I know goto is out of the question and duplicity of any kind is sloppy code. So how would i go about doing this please. I think i need somehting in the ctype.h right?
Code:
/* guessing game program
* (c) 2003 practical applications
* To be refactored including:
* user input validation on scanf()
* calling only one function in main()
* preprocessor directives validating and executing platform
specific code
* srand to generate better random numbers */
/* the game */
#include <stdio.h>
#define RUNNING 1
int main()
{
int number;int guess;int tries = 0;
char name[15];
system("TITLE Stupid guessing game");
printf("Hey, whats your name?");
gets(name); /* in case it is alpha numeric */
system("cls");
printf("Hey %s, we are gonna play a game\n\n", name);
system("pause");
system("cls");
system("COLOR 74");
while(RUNNING)
{
number = rand() % 100 + 1;
printf("guess a number between 1 and 100: ");
gets(guess); /* works better but still have a warning */
tries++;
if(guess > number)
printf("too high. The number was %d\n", number);
else if(guess < number)
printf("too low. The number was %d\n", number);
else if(guess == number)
printf("perfect you only need %d tries to guess!\007\007\007\n", tries);
}
return 0;
system("PAUSE");
}