Guessing Game

Hey I'm new to programming and am stuck on one of my assignments. Here's what we have to do:
The rules of the game are as follows:

* The user will be asked to pick a number in the range 1 through 100 (inclusive), and the computer gets six tries to guess which number the user picked.
* After each guess the user must indicate if the number they have chosen is lower than, higher than, or equal to the computer's latest guess.
* The player wins the game if the computer fails to guess the correct number in six tries, the computer wins otherwise.

The player should be able to play multiple games in a row, with the computer keeping track of how many games resulted in player wins and losses.

Here is what I've done so far:
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
using namespace std;

//Declare constants for range of values, # of guesses
const int LowBound = 1;
const int HighBound = 100;
const int GuessMax = 6;

int main()
{

    //Tell player about the game
    cout << "Welcome to the Guessing Game!" << endl;
    cout << "The point of the game is for me to guess" << endl;
    cout << "the number that you're thinking of." << endl;
    cout << "I have six guesses or else you win!" << endl;

    //Declare variables for scoring
    int CompWins = 0;
    int UserWins = 0;

    //See if the player want to play/continue playing
    char PlayAns;
    cout << "would you like to play?" << endl;
    cout << "Enter 'Y' for yes, 'N' for no" << endl;
    cin >> PlayAns;

    For (PlayAns == 'Y'){

        // Set up variables to store the known range of the valid integer values.
        int Lower = LowBound;
        int Higher = HighBound;

        // Use a variable to hold the current guess.
        int Guess;

        /*Use a variable to store the users responses. ( L = Too low.*/
        /* H = Too high. Anything else = correct.)*/
        char = Feedback;

        // Make the first guess.
        Guess = (Lower + Higher) / 2;
        cout << "I guess" << Guess << endl;
        cout << "Please enter H if I guessed too high, L for too low, " << endl;
        cout << "and anything else if I am correct." << endl;
        cin >> Feedback;

        //See if we are right, or keep guessing.
        If (Feedback = L) {
            //The guess is too low so the last guess becomes the new Higher
            Higher = Guess;
        } Else If (Feedback = H) {
            // The guess is too high so the last guess becomes the new Lower
            Lower = Guess;
        } Else {
            // I got it right.
            cout << "I won in one guess." << endl;
            cout << "Computer's Score: " << NewScoreC = CompWins + 1 << endl;
            cout << "User's Score: " << NewScoreU = UserWins << endl;
            return 0;
        }  

        // Calculate the second guess.
        Guess = (Lower + Higher) / 2;
        cout << "I guess" << "Guess" << "Please respond H, L, or R." << endl;
        cin >> Feedback;
        If (Feedback = L) {
            Higher = Guess;
        } Else If (Feedback = H) {
            Lower = Guess;
        } Else {
            cout << "I won in two guesses." << endl;
            cout << "Computer's Score: " << NewScoreC = CompWins + 1 << endl;
            cout << "User's Score: " << NewScoreU = UserWins << endl;
            return 0;
        }

        // Calculate the third guess.
        Guess = (Lower + Higher) / 2;
        cout << "I guess" << "Guess" << "Please respond H, L, or R." << endl;
        cin >> Feedback;
        If (Feedback = L) {
            Higher = Guess;
        } Else If (Feedback = H) {
            Lower = Guess;
        } Else {
            cout << "I won in three guesses." << endl;
            cout << "Computer's Score: " << NewScoreC = CompWins + 1 << endl;
            cout << "User's Score: " << NewScoreU = UserWins << endl;
            return 0;
        }

        // Calculate the fourth guess.
        Guess = (Lower + Higher) / 2;
        cout << "I guess" << "Guess" << "Please respond H, L, or R." << endl;
        cin >> Feedback;
        If (Feedback = L) {
            Higher = Guess;
        } Else If (Feedback = H) {
            Lower = Guess;
        } Else {
            cout << "I won in four guesses." << endl;
            cout << "Computer's Score: " << NewScoreC = CompWins + 1 << endl;
            cout << "User's Score: " << NewScoreU = UserWins << endl;
            return 0;
        }

        // Calculate the fifth guess.
        Guess = (Lower + Higher) / 2;
        cout << "I guess" << "Guess" << "Please respond H, L, or R." << endl;
        cin >> Feedback;
        If (Feedback = L) {
            Higher = Guess;
        } Else If (Feedback = H) {
            Lower = Guess;
        } Else {
            cout << "I won in five guesses." << endl;
            cout << "Computer's Score: " << NewScoreC = CompWins + 1 << endl;
            cout << "User's Score: " << NewScoreU = UserWins << endl;
            return 0;
        }

        // Calculate the FINAL GUESS.
        cout << "You picked" << "Guess" << endl;
        cout << "Right? (Y or N)" << endl;  
        cin >> Feedback;
        If (Feedback != Y) {
            cout << "You beat me!" << endl;
        } Else If (Feedback == Y) {
            cout << "I won!" << endl;
            cout << "Computer's Score: " << NewScoreC = CompWins << endl;
            cout << "User's Score: " << NewScoreU = UserWins + 1 << endl;
            return 0;
        }
    } While (PlayAns = 'N'){
        cout << "Thanks for Playing!" << endl;
        return 0;
    }      
}



If anyone can help me out I would greatly appreciate it.
What is the question?
Although a more specific question would be appreciated, remember that C++ is a case-sensitive language so stuff like this:

1
2
3
If (Feedback != Y) {
            cout << "You beat me!" << endl;
        } Else If (Feedback == Y) {


should not even work. It should be:

1
2
3
if (Feedback != 'Y') { //you were also missing the single quotes for a character
            cout << "You beat me!" << endl;
        } else if (Feedback == 'Y') { //same as previous comment 


The variables can be capitalized as long as you declare them as such.

EDIT: Another quick skim revealed lots of errors. Look at the compiler errors for help on fixing it up.
Last edited on
Topic archived. No new replies allowed.