Help with number guessing

Here's my current code and I am stuck completing my playOneGame(). Could someone please guide me towards the right path?

A sample run of the program might look like this, with the user inputs below:

/** Sample Code **/
Think of a number between 1 and 100.
Is it 50? (h/l/c): h
Is it 75? (h/l/c): h
Is it 88? (h/l/c): l
Is it 81? (h/l/c): c
Great! Do you want to play again? (y/n): y
Think of a number between 1 and 100.
Is it 50? (h/l/c): l
Is it 25? (h/l/c): h
Is it 37? (h/l/c): c
Great! Do you want to play again? (y/n): n

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
using namespace std;

/***** Function declaration (prototype) *****/
void playOneGame();
char getUserResponseToGuess(int);
int getMidpoint(int, int);
bool shouldPlayAgain();

/***** main function *****/
int main() {

        do {
          playOneGame();
        } while (shouldPlayAgain());

        return 0;
}

/***** Function definition (header and body) *****/

// The playOneGame() function has a return type of void. It implements a complete guessing game on the range of 1 to 100. getUserResponseToGuess(), and getMidpoint() should be called inside the playOneGame()

void playOneGame()
{
        int low = 1;
        int high = 100;
        int previous;
        int num;
        char response;

        cout << "Think of a number between 1 and 100." << endl;
        response = getUserResponseToGuess(int guess);
        while (response != 'c')
        {
                if (response == 'l')
                {
                        // calculate midpoint
                        num = midpoint(guess, high);
                        previous = guess;
                }
                else if (response == 'h')
                {
                        // calculate midpoint
                        num = midpoint(guess, high);
                        previous = guess;
                }
        else
        {
                shouldPlayAgain();
        }
}

// This function prompts the user with the phrase “is it <guess>? (h/l/c): “ with the value replacing the token <guess> and returns a char. The char should be one of three possible values: ‘h’, ‘l’, or ‘c’.

char getUserResponseToGuess(int guess)
{
        char input;
        cout << "Is it " << guess << "? (h/l/c): ";
        cin >> input;
}

// This function accepts two integers, and returns the midpoint of the two integers.
int getMidpoint(int low, int high)
{
        int midpoint;
        midpoint = ((low + high)/2);
        return midpoint;
}

// The shouldPlayAgain() function has a bool return type. It prompts the user to determine if the user wants to play again, reads in a character, returns true if the character is a ‘y’, and otherwise returns false.

bool shouldPlayAgain()
{
        char again;
        bool status;
        cout << "Would you like to play again" << endl;
        cin >> again;
        if (again == 'y' || 'Y') {
                bool status = true;

        } else {
                bool staus = false;
        }
        return status;

}
What exactly do you need guidance with? In a guessing game like the one you're creating, you'll need a way to generate a random number. You can do this by seeding the random number generator and then use rand() or mt19937 (mersenne twister engine) to obtain a random value from 1 to 100. You can use either one, use mt19937 if you need a reasonable level of unpredictability. Though, for a simple guess my number game, rand() should do.
Topic archived. No new replies allowed.