I actually posted this code already for another problem and got some good help on it. But theres one more thing id like to do to make the input even better able to handle user error, but im not sure if its possible or at least easy. I need the function to return a large positive number. As of right now, it can handle users entering characters, but what if the user enters a negative number? is there a way to check to see if what is coming in is negative before the sign gets lost in conversion to unsigned"ness"?
Code:unsigned long getNum(char prompt[80]) { unsigned long darts; printf("%s", prompt); while((scanf("%lu", &darts)) != 1) { while(getchar() != '\n') ; printf("\nThis is not an acceptable entry. please try again.\n\n"); printf("%s", prompt); } return darts; }



LinkBack URL
About LinkBacks


