Reputation: 309
So I wish to make it so you cannot enter a number such as 0 or 11. I am using netbeans 8.1 (GNU cygwin)
. I have found that the while loop is not being used, and that the terminal runs a successful build regardless of the loop made to ensure out of bound numbers are not existent.
int main(int argc, char** argv) {
int x;
int guess = 0;
srand(time(NULL));
x = rand() % (10) + 1;
printf("random number is %d. \n", x);
printf("whats your guess? 3 tries. between 1 and 10 \n");
scanf("%d", guess);
while (guess >10 || guess < 0){
printf(" your guess is out of the bounds (1 to 10) re enter: \n");
scanf("%d", guess);
}
return (EXIT_SUCCESS);
}
Any ideas? I intend to make several comparisons to 'x' later.
Upvotes: 0
Views: 70
Reputation: 309
Simply needs a & (ampersand) in the scan f statement.
scanf("%d", &guess);
Upvotes: 1