C++代写:CIS22A Nested Loops

基础C++作业代写,练习嵌套循环的使用方法。

Requirement

Write a C++ program CIS22A-Lab6-XXXXX.cpp that implements a simple number guessing game with multiple questions / answers. For each game, the program generates a random number between 1 and 10. User enters an answer from 1 and 10. If the user input number matches the generated number, then print a message to inform users that he/she has a correct guess. If the guess is not correct, allow the user to have two more chances to guess the correct number. At any time, if users enter 0, then the program should display the session summary and exits. The program should keep track of the wins and losses and print the counts when user chooses to exit by entering 0.
The program should generate a new random number only after user enters the correct guess or after user has tried 3 times and did not have the right guess. Do not ask user for a yes/no confirmation after each game because the 0 input value will serve as the sentinel to stop the continuous game.

Here is a sample run using command line.

At the program start, it shows:

"Welcome to the number guessing game.
For each game, you have at most 3 chances to guess a secret number from 1 to 10."

The first time, when a new question is asked, the program displays:

"Enter a number from 1 to 10. Enter 0 to exit:"

When users give a wrong guess, it shows:

Not correct, try again:

When users give a wrong answer after the third trials for the same question, the program displays:

"Not correct. You have reached your third trials. The correct number is X."
"Lets start a new secret number"

When users answer with the correct number, it shows this prompt:

"Congratulation, correct! Let's start a new secret number."

When users hit 0, the game summary is displayed:

Here is your game summary:

Total games:           5
Total game wins:       3
Total game losses:     2

Notes

  1. Use the function rand() to generate random numbers and srand() to intialize the generator.
  2. Also use “time.h” and use the srand() to generate a random seed for the random generator. The srand() should be called only once outside the loop before the game starts.
  3. In main(), you can use a “while” or “for” loop to gets inputs.
  4. To control the number of maximum trial answer per question, you can use a nested loop inside the main “while” loop.
  5. Generate a new random number only when a new game starts after users either have entered the correct answer or users have exceeded the 3 trials.
  6. For the count of losses, update the count only when users have exceeded the maximum 3 trials. Do not count as a loss if users have not finished the 3 trials.

Add Comment at the top of yor program:

1
2
3
4
5
/***************************************
/* Author:
/* Description:
/*
/***************************************

To run my game with “cheating mode”, open the Windows command console , change to folder where you save the sample game, and run with the /c option

cd /MyDocuments/lab-6
lab-6 /c