I have tried for sometime now with this exercise
Build a number guessing game that uses input validation
(isdigit() function) 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 wrote the following code
Code:
#include <stdio.h>
#include <ctype.h>
int main()
{
int iRandomNum;
int iResponse;
iRandomNum = (rand()%10)+1;
printf("\nGuess a number between 1 and 10: ");
scanf("%d", &iResponse);
if (isdigit(iResponse))
;
else
{
printf("You didn't enter a number\n\n");
return 0;
}
if (iResponse == iRandomNum) {
printf("\nYou guessed right\n");
}
else {
printf("\nSorry, you guessed wrong\n");
printf("The correct guess was %d\n", iRandomNum);
}
}
I can't get both if statements to work after one another. I also get a warning ,
".c(10): warning #2027: Missing prototype for 'rand'."