so i'm creating program that's guessing game. it's supposed ask player 1 enter number between 0 , 99, if enter outside of code should ask them retry this.
then ask number of guesses/attempts player 2 has enter think number is. if it's high program so, if it's low program so. if it's right- player 2 wins , if run out of guesses program too.
my problem second half of code. i'm trying fit in number of guesses remaining guesses. loop isn't working; here's code:
int secretnumber; int guesses; int secretnumberguess; int remainingguesses; while (1) { printf("player 1: type number between 0 , 99 , press return:\n"); scanf(" %d",&secretnumber); if (secretnumber > 99 || secretnumber < 0) { printf("secret number cannot greater 99 or below 0.\n"); continue; } break; } printf( "type number of guesses player 2 gets , press return: \n"); scanf("%d",&guesses); remainingguesses = guesses - 1; while (remainingguesses != 0) { printf("player 2: type guess , press return (guesses remaining:%d):\n",&remainingguesses); scanf(" %d",&secretnumberguess); if (secretnumberguess > secretnumber) { printf("your guess greater secret number.\n"); else if (secretnumberguess < secretnumber) printf("your guess less secret number.\n"); else (secretnumberguess == secretnumber) printf("your guess equal secret number. win!\n"); continue; } break; } if (remainingguesses == 0) printf("sorry out of guesses. lose.\n");
i'm entirely new , trying debug , fix code. loops nightmare me when throw if statements mix. realize i'm incompetent , apologize me i'm totally confused on second half of code.
first off, code:
while (remainingguesses != 0) { printf("player 2: type guess , press return (guesses remaining:%d):\n",&remainingguesses); scanf(" %d",&secretnumberguess);
is wrong. when using printf
statement , trying input variable in statement, don't need put &
in it.
so need change code to:
while (remainingguesses != 0) { printf("player 2: type guess , press return (guesses remaining:%d):\n",remainingguesses); scanf(" %d",&secretnumberguess);
you need remove &
in printf
statement. use &
store variable.
Comments
Post a Comment