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

- Step 1: Let the user enter the last number by simply add a parameter named las

ID: 3630353 • Letter: #

Question

- Step 1: Let the user enter the last number by simply add a parameter named last:


bool NumberGuessing(int last);

Now you can call NumberGuessing in main() like the following examples assuming that the number to guess is 7. But you entered a wrong 'y' or 'n', either accidentally or intentionally


Game starts:
I can guess a number [1..n] in your mind. Enter n you want: 10
Is it 5? n
Is it bigger than 5? y
Is it 8? n
Is it bigger than 8? n
Is it 6? n
Is it bigger than 6? y
Is it 7? n
Is it bigger than 7? n
Is it 6?
...

or


Game starts:
I can guess a number [1..n] in your mind. Enter n you want: 10
Is it 5? n
Is it bigger than 5? y
Is it 8? n
Is it bigger than 8? n
Is it 6? n
Is it bigger than 6? n
Is it 5? n
Is it bigger than 5? y
Is it 5?
...

Unfortunately, the game can't recognize the error or cheating happened in processing. In the first example, you answer NO to the only choice of 7, but the game asks 6 at the second time again. This is definitely not a logic deduction. In the second example, you answer NO to 6 and continue to choose less than 6, a cheating obviously. Again, the game can't detect it and be stupid to ask 5 at the second time.

- Step 2: As we can see, the function NumberGuessing() doesn't return any meaningful false value. Now we can make use of this false value to indicate an error. We need to let the game detect the invalid input. So you have to add error handling of above situations in NumberGuessing(). It returns true if working fine to win, false if an error or cheating detected. You can have different ways to deal with it. The following are two alternatives, still assuming that the number to guess is 7.

You can make it like this when call NumberGuessing():


Game starts:
I can guess a number [1..n] in your mind. Enter n you want: 10
Is it 5? n
Is it bigger than 5? y
Is it 8? n
Is it bigger than 8? n
Is it 6? n
Is it bigger than 6? y
Is it 7? n
You are cheating, bye.
Press any key to continue . . .

I can guess a number [1..n] in your mind. Enter n you want: 10
Is it 5? n
Is it bigger than 5? y
Is it 8? n
Is it bigger than 8? n
Is it 6? n
Is it bigger than 6? n
You are cheating, bye.
Press any key to continue . . .

A smarter NumberGuessing() should ask 7 immediately after you say No to 6:


Game starts:
I can guess a number [1..n] in your mind. Enter n you want: 10
Is it 5? n
Is it bigger than 5? y
Is it 8? n
Is it bigger than 8? n
Is it 6? n
Is it 7? n
You are cheating, bye.

Explanation / Answer

well, this is kinda messy... It works fine when I checked from 1 to 10 of n=10 ****Program output:**** Game starts: I can guess a number [1..n] in your mind. Enter n you want: 10 Is it 5? n Is it bigger than 5? y Is it 8? n Is it bigger than 8? n Is it 6? n Is it 7? n You are cheating, bye. ****Solution**** #include using namespace std; int main() { // PROTOTYPES bool NumberGuessing(int last); // LOCAL DECLARATIONS int last; // PROCEDURES cout last; cin.ignore(); if (!NumberGuessing(last)) { cout