-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumberGuessingGame.cpp
More file actions
63 lines (54 loc) · 1.46 KB
/
Copy pathnumberGuessingGame.cpp
File metadata and controls
63 lines (54 loc) · 1.46 KB
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
//Amelie Cameron Assignment 10
//This program is a classic number guessing game. The program guesses a user's number between 1 and 100. Unlike the previous assignment, this one uses a NumberGuesser class that contains all of the logic for remembering the current state of the programs guesses and implements the binary search algorithm.
#include <iostream>
#include <algorithm>
#include "NumberGuesser.h"
using namespace std;
int main()
{
char value;
bool done = false;
bool playAgain = true;
char play;
NumberGuesser guesser (1, 100);
while(playAgain)
{
guesser.reset();
cout << "Think of a number between 1 and 100" << endl;
while(!done)
{
int imid = guesser.getCurrentGuess();
cout << "Is the number " << imid << "? (h/l/c) :" << endl;
cin >> value;
if(value == 'h')
guesser.higher();
else if(value == 'l')
guesser.lower();
else if(value == 'c')
{
cout << "You picked " << imid << "? Great pick. " << endl;
cout << "Would you like to play again? (y/n)" << endl;
cin >> play;
if(play == 'y') {
playAgain = true;
done = true;
} else if(play == 'n')
{
playAgain = false;
done = true;
cout << "Thanks for playing!" << endl;
}
else
{
cout << "Incorrect key. Goodbye." << endl;
playAgain = false;
done = true;
}
}
else
cout << "Incorrect key. Please enter h, l, or c." << endl;
}
done = false;
}
return 0;
}