-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhigh_low.php
47 lines (43 loc) · 882 Bytes
/
high_low.php
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
<?php
$guessed = 1;
$confirm = 'yes';
$userInput2 = 'yes';
if ($argc >= 3) {
$rand = rand($argv[1], $argv[2]);
}
else {
$rand = rand(0, 100);
}
echo $rand. PHP_EOL;
do {
fwrite(STDOUT, 'Guess? ');
$userInput = fgets(STDIN);
if ($guessed >= 7) {
echo 'You lose!';
break;
}
if ($userInput == $rand) {
fwrite(STDOUT, "You Win!\n");
echo "You guessed $guessed times!" . PHP_EOL;
fwrite(STDOUT, 'Type yes to play again! ');
$userInput2 = trim(fgets(STDIN));
echo $userInput2;
if ($argc >= 3) {
$rand = rand($argv[1], $argv[2]);
}
else {
$rand = rand(0, 100);
}
$rand;
echo $rand. PHP_EOL;
}
else if ($userInput <= $rand) {
echo "Higher" . PHP_EOL;
$guessed++;
}
else if ($userInput >= $rand) {
echo "Lower" . PHP_EOL;
$guessed++;
}
} while ($userInput2 == $confirm);
?>