Two player guessing game
#includeint main() { int number = 0, guess = 0; int counter= 0; /*to count user attemps*/ /* asking player1 to enter a number */ printf("Player 1 !! enter a number between 1 to 10 :"); scanf("%d" , &number); /* asking player2 to guess the number player1 entered */ printf("Player 2 !! Guess the number: "); scanf("%d" , &guess); while(guess != number) /* if player2 guessed wrong ask again */ { counter++; printf("Wrong \n"); printf("Player 2 !! Guess the number again.."); scanf("%d",&guess); } printf("great!! u guessed after %d wrong attempts..", counter); return 0; }
No comments:
Post a Comment