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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
 
class Person {
    string p[2];
    int index;
public:
    Person() { p[0= "류현진"; p[1= "손연재"; index = 0; }
    string getName();
};
 
string Person::getName() {
    if (index == 0) {
        index++;
        return p[index - 1];
    }
    else if (index == 1) {
        index = 0;
        return p[index + 1];
    }
}
 
class UpAndDownGame {
    static int low, high;
public:
    UpAndDownGame() { srand((unsigned)time(0)); }
    static void playGame();
};
 
int UpAndDownGame::low = 0;
int UpAndDownGame::high = 99;
 
void UpAndDownGame::playGame() {
    Person p;
    string name = p.getName();
    int number, result = rand() % 100;
    cout << "UP & Down 게임을 시작합니다." << endl;
    while (1) {
        cout << "답은 " << low << "과 " << high << "사이에 있습니다." << endl;
        cout << name << ">>";
        cin >> number;
        if (number == result) {
            cout << name << "이(가) 이겼습니다!!" << endl;
            break;
        }
        number > result ? high = number : low = number;
        name = p.getName();
    }
}
 
int main() {
    UpAndDownGame user;
    user.playGame();
}
cs


+ Recent posts