-
Notifications
You must be signed in to change notification settings - Fork 0
/
guess_game.dart
39 lines (35 loc) · 1.02 KB
/
guess_game.dart
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
import 'dart:io';
import 'dart:math';
void main() {
int guess_number;
int increment = 4;
int value;
int small = 1;
int large = 50;
guess_number = Random().nextInt(50);
print(guess_number);
print("guess the value between 1-50: ");
value = int.parse(stdin.readLineSync()!);
while (0 < increment) {
if (guess_number < value) {
large = value;
print("You have ${increment} chances remains");
print("the guess value is larger than you enter");
print("guess the value between 1-${large}: ");
value = int.parse(stdin.readLineSync()!);
} else if (guess_number > value) {
small = value;
print("You have ${increment} chances remains");
print("the guess value is smaller than you enter");
print("guess the value between $small-${large}: ");
value = int.parse(stdin.readLineSync()!);
} else if (guess_number == value) {
print("You win the game!");
break;
}
increment--;
}
if (guess_number != value) {
print("You lose the game!");
}
}