I'm currently reading C Programming for the Absolute Beginner and am stuck on one of the chapter questions. This is a really simple question but I am stuck.
Problem:
Build a number guessing game that uses input validation (isdigit() funciton) to verify that the user has entered a digit and not a non-digit (letter). Store a random number between 1 and 10 into a variable each time the program is run. Prompt the user to guess a number between 1 and 10 and alert the user if he was correct or not.
I've already tried to run the program and debug it with no luck. I'm missing something from the text and obviously didn't apply that here.Code:#include <stdio.h>
#include <ctype.h>
main()
{
int iNumber = 0;
int iAnswer = 0;
srand(time());
iAnswer = (rand() % 10) + 1;
printf("Guessing Game\n");
printf("\nGuess a number from 1 to 10: ");
scanf("%d", &iNumber);
if ( isdigit(iNumber) > 10 || < 1 )
printf("Enter a number between 1 and 10");
if (iNumber == iAnswer)
printf("\nYou guessed right!\n");
else
printf("\nSorry, you guessed wrong\n");
printf("The correct guess was %d\n", iAnswer);
}
Any help will be greatly appreciated,
-Peter

