-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguess.cpp
More file actions
38 lines (31 loc) · 959 Bytes
/
guess.cpp
File metadata and controls
38 lines (31 loc) · 959 Bytes
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
muskan kapoor <muskankapoor016@gmail.com>
Fri, Jul 6, 4:17 PM (23 hours ago)
to me
#include <iostream>
#include <cstdlib>
int main(){
using namespace std;
int the_number;
int guess;
int tries;
the_number = rand() % 50 + 1;
cout << "Let's play a game!";
cout << "I will think of a number 1-10. Try to guess it.";
cout << endl;
cin >> guess;
for (tries = 0; ; tries++) {
if (guess == the_number){
cout << "You guessed it!";
//cout << "And it only took you " << tries << " tries.\n";
break;
}
else if (guess < the_number){
cout << "Higher";
cin >> guess;
}
else if (guess > the_number){
cout << "Lower";
cin >> guess;
}
}
}