Guessing Game Help

How can i separate this game into 4 rounds please i need immediate help, this program is due tomorrow.

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
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;



int main()
{
    srand(time(0));


    int start;
    int end;

    cout<<"Enter the starting value for what your guess can be between ";
    cin>>start;
    cout<<"Enter the ending value for your guess can be between ";
    cin>>end;

    int range;
    range=(start-end);
    int secretNumber = (rand() % range) + start;

    int tries = 0;
    int round;
    int guess;





    range=(start-end);




for(int round=0; round<4; round++){

    do
    {
        cout << "Enter a guess for game "<<tries+1<<" ";
        cin >> guess;
        ++tries;



            if (guess > secretNumber)
            {
                cout << "Too high!" << endl << endl;
            }

            if (guess < secretNumber)
            {
                cout << "Too low!" << endl << endl;
            }
             if (guess == secretNumber)
    {
        cout << "You win! You got it in " << tries << " tries!" << endl;
    }
    } while (guess = secretNumber);

    if (guess == secretNumber)
    {
        cout << "You win! You got it in " << tries << " tries!" << endl;

    }
    else
    {
        cout << "You lose! You used all " << tries << " of your tries." << endl;
    }
}
    return 0;
}

Last edited on
You havent told us the problem you are having. However, after a quick glance i see that your do-while loop may not be doing what it should do. I think what you want is to
1
2
3
4
do
{
     ...
}while( guess != secretNumber);


The above code will loop while the user has not guessed the secretNumber.
No its right, i just need the program i have right now in 4 rounds.

For every round you need to guess until you get the number which i have already done but now i need the program to keep on continuing after i have guessed the number 1st time.



Well, your current loop is using the assignment operator( = ) instead of the equal-to operator (== ). I cant imagine that this is intentional.
Last edited on
Topic archived. No new replies allowed.