View difference between Paste ID: yJFqLyEZ and k1J5GwBe
SHOW: | | - or go back to the newest paste.
1
// Лаба 2 здача 3
2
// Используя оператор do..while: угадать число от 1 до 1000 не более чем за 10 попыток (вводится предполагаемое число, программа "отвечает": искомое больше/меньше или отгадано)
3
4
#include <bits/stdc++.h>
5
 
6
using namespace std;
7
 
8
int main() {
9-
    string s;
9+
    srand(time(0));
10-
    int x = 500;
10+
    int x = int(rand()) % 1000;
11-
    int dob = 500;
11+
    //cout << x;
12-
    do {
12+
    for (int i = 0; i < 10; i++) {
13-
        cout << x << "\n";
13+
        int now;
14-
        cin >> s;
14+
        cout << "You have " << 10 - i <<  " attempts \n";
15-
        if (s == "more") {
15+
        cin >> now;
16-
            dob = (dob + 1) / 2;
16+
        if (now == x) {
17-
            x = x + dob;
17+
            cout << "You Win!";
18
            return 0;
19-
        } else {
19+
20-
            dob = (dob + 1) / 2;
20+
        if (now > x) {
21-
            x = x - dob;
21+
            cout << "Less \n";
22
        }
23-
    } while (s != "win");
23+
        if (now < x) {
24
            cout << "More \n";
25
        }
26
    }
27
    cout << "You Lose!";
28
    return 0;
29
}