Well I'm certainly digging up an old thread too lol. I have just started this book myself and am frustratingly working on the same problem. I found this thread after extensive searching for information and ideas. I have gone over and over this problem so much that I wonder if it's possible using only the lessons learned from the first three chapters. The book's website has a download available for fixing errors found inthe book but I have still come across other small errors just in the first three chapters. I would be very keen to hear what you thought of "C for Dummies" Nimbuz - assuming that after two years you will be reading this.
I have mine sort of working but I don't feel that it is truly correct - if the user has entered a character the program says to "please enter a digit" but still continues on with the rest of the program.
Would appreciate any advice if anyone is reading this after so longCode:#include <stdio.h> #include <stdlib.h> #include <time.h> #include <ctype.h> main() //Guess a number from 1 to 10 { int iRandomNum = 0; //int iResponse = 0; char cResponse = '\0'; srand(time(NULL)); iRandomNum = (rand() % 10) + 1; printf("\nGuess a number from 1 to 10: "); //scanf("%d", &iResponse); scanf("%c", &cResponse); if (isdigit(cResponse) == 0) { // check to see if user has entered a digit printf("\nYou need to enter a digit please. \n"); } if (cResponse == iRandomNum) { // if user input = random number printf("\nYou are correct!\n"); } else printf("\nBummer dude\n"); printf("\nThe correct number was %d\n", iRandomNum); }![]()



LinkBack URL
About LinkBacks



