-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_ file 1 (1).txt
More file actions
36 lines (29 loc) · 785 Bytes
/
Copy pathmain_ file 1 (1).txt
File metadata and controls
36 lines (29 loc) · 785 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
#include <iostream>
using namespace std;
int main()
int chosenNumber = 7;
int userGuess = 0;
int attempts[100];
int attemptCount = 0;
while loop
while (userGuess != chosenNumber) {
cout << "Enter your guess: ";
cin >> userGuess;
attempts[attemptCount] = userGuess;
attemptCount++;
if (userGuess > chosenNumber) {
cout << "Too high" << endl;
}
else if (userGuess < chosenNumber) {
cout << "Too low" << endl;
}
else {
cout << "Correct" << endl; }
}
cout << "\nYour attempts were: ";
for (int i = 0; i < attemptCount; i++) {
cout << attempts[i] << " ";
}
cout << endl;
return 0;
}