Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(void)
- {
- int iRandomNum;
- int iGuess;
- srand(time(NULL));
- iRandomNum = (rand() % 10);
- printf("Guess a number between 1 and 10:");
- scanf("%d", &iGuess);
- // isdigit function expects a character so the guess value has to be ascii value of the digit character
- iGuess += 48;
- if (isdigit(iGuess)){
- iGuess -=48; // change back to the original value for comparison with random number
- if (iGuess == iRandomNum){
- printf("You Guessed Correctlyn");
- }
- else{
- printf("The correct answer was %dn",iRandomNum);
- printf("You guessed %dn",iGuess);
- }
- }
- else{
- printf("This is not a digit!n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement