Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are required tocreate a game that will operate as follows: • The player will

ID: 3617128 • Letter: Y

Question

You are required tocreate a game that will operate as follows:

•    The player will guess a number between 1and 9
•    The computer will then select a randomnumber between 1 and 9
•    The program will then compare the twonumbers and if they are equal the player wins and his/her score isincreased by 1. If they are not equal the computer score isincreased by 1.
•    The player can exit the game by entering-1. When this occurs the player's score and the computer score isdisplayed on the screen and the overall winner is congratulated viaan appropriate message on the screen. You are required tocreate a game that will operate as follows:

•    The player will guess a number between 1and 9
•    The computer will then select a randomnumber between 1 and 9
•    The program will then compare the twonumbers and if they are equal the player wins and his/her score isincreased by 1. If they are not equal the computer score isincreased by 1.
•    The player can exit the game by entering-1. When this occurs the player's score and the computer score isdisplayed on the screen and the overall winner is congratulated viaan appropriate message on the screen.

Explanation / Answer

// Guessing Game // March 1st 2010 // Created By Nic Raboy
#include <stdio.h> #include <stdlib.h> #include <time.h>
int main() { srand(time(NULL)); // Seed our randomizer with the systemtime int playerguess = 0; int computerguess = 0; int playertotal = 0; int computertotal = 0; // Loop until our player guess is -1 while(playerguess != -1) { printf("Guess A Number 1-9 (-1 Ends)> "); scanf("%d", &playerguess); // Input an integer if(playerguess == -1) { break; } // End the program if-1 computerguess = (rand() % 9)+1; // A random number between 1and 9 // If player wins then increase score otherwise increasecomputer score if(playerguess == computerguess) { playertotal++; } else { computertotal++; } } // Display the total scores printf("Your Score = %d Computer Score = %d ", playertotal,computertotal); // Determine who wins if(playertotal > computertotal) { printf("You Win "); } else { printf("Computer Wins "); } return 0; } --------------------------------------------------------- I think this is what you want. I commented the code, butif you have any questions let me know.
Nic Raboy
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote