Hi!
For this program the computer will be guessing the number that the user have chosen, from 1 to 10.
It will need to keep track of the number of guesses that the computer makes before it guesses correctly.
This is what I have done by now:
The output should look like this:Code:int main() { int num, count; char x, y; do{ count = 0; printf("Please pick a number between 1 and 10...\n"); printf("Ready to Play? "); scanf("%s", &x); while(x == 'y' || x == 'Y') { num = 1; printf("Is your number %d? ", num); scanf("%s", &x); num++; count++; while(x == 'n' || x == 'N') { printf("Is your number %d? ", num); scanf("%s", &x); count++; num++; } printf("You chose %d and it took me %d attempts.\n", num, count); printf("\n"); printf("Shall we play again? "); scanf("%s", &y); printf("\n"); } }while(y == 'y' || y == 'Y');
But in this case I got an invalid output in the integer that displays the number since it doesn't increase the integer, here is the example:Code:Please pick a number between 1 and 10... Ready to play? Y Is your number 3? N Is your number 8? N Is your number 5? Y You chose 5 and it took me 3 attempts. Shall we play again? Y Please pick a number between 1 and 10... Ready to play? Y Is your number 3? Y You chose 3 and it took me 1 attempt. Shall we play again? N
As you can see, the number doesn't increase...Code:Please pick a number between 1 and 10... Ready to Play? Y Is your number 1? N Is your number 1? N Is your number 1? Y You chose 1 and it took me 3 attempts. Shall we play again? Y Please pick a number between 1 and 10... Ready to Play? Y Is your number 1? Y You chose 1 and it took me 1 attempts. Shall we play again? N
Also it will be very appreciated if someone can gave me some advises of how to make random or not sequential numbers.
i.e. Instead of going 1, 2, 3, 4, 5, 6, 7, 8, 9 , 10, etc. The output be 3, 8, 5, 6, 2, 4, 1, 7, 10, 9.
Thanks for your help and happy Programming!