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 |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 실습문제 6장 2번 (0) | 2018.05.10 |
|---|---|
| 명품 C++ Programming 실습문제 6장 1번 (0) | 2018.05.09 |
| 명품 C++ Programming 실습문제 5장 8번 (0) | 2018.05.09 |
| 명품 C++ Programming 실습문제 5장 7번 (0) | 2018.05.09 |
| 명품 C++ Programming 실습문제 5장 6번 (0) | 2018.05.09 |