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

In this assignment, you are to write a program that guesses what you have in you

ID: 3818475 • Letter: I

Question

In this assignment, you are to write a program that guesses what you have in your mind. No, computers can't read your mind, but at least guess a number you have in mind given that you tell the program whether the number the program guessed is higher or lower than your number. Since humans are much more creative than the computer applications, we will level the playing field by limiting the number we select to be in between l and 100. The program should work as following: 1. You will pick a number between 1 and 100. This number should never be used in your program 2. The program should pick a random number in between 1 and 100. 3. The program asks user whether the number is comect, higher, or lower. 4. If it is the correct guess, print "Correct guess" and exit out of the program. 5. If not correct, answer "h", or "I" to indicate the guess is either higher or lower than the correct number. 6. Iflower, then the next number should be higher than the previous guess. 7. If higher, then the next number should be lower than the previous guess. 8. Repeat steps 3 through 7 until the correct guess is made. 9. The program should keep track of the number guesses made until the correct guess. 10. Capture screen outputs ofall guesses and responses along with the final number of guesses taken, Submit your source code and output screen capture.

Explanation / Answer

#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;

int main()
{
    char ch;
    srand((unsigned)time(0));
    int i, j,
    struct node {
int x;
node *next;
    };
    struct node *head, *temp, *p;
    int guessed_numbers
    guess_count = 0;
    ch = 'g';
    i = (rand()%100)+1;
    head = NULL;
    while (ch != 'c') {
cout << i << " ";
        if (head == NULL){
     head = new node;
            head->x = i;
            head->next = NULL;
        }
        else {
           p = head;
           while (p->next != NULL)
                 p = p->next;
           temp = new node;
           temp->x = i;
           temp->next = NULL;
           p->next = temp;
        }
cin >> ch;
        guess_count++;
switch(ch) {
  case 'h':
   j = (rand()%100)+1;
   while ( j < i) {
                            j = (rand()%100)+1;
   }
   i = j;
  case 'l':
   j = (rand()%100)+1;
   while ( j > i) {
                            j = (rand()%100)+1;
   }
   i = j;

}
    }
    cout << "Correct Guess" << " ";
    p = head;
    while (p ! = NULL){
    cout << p->x;
    p = p->next;
    }
    cout << " ";
    cout << "The number of guesses:" << guess_count;
}