-
Notifications
You must be signed in to change notification settings - Fork 0
/
for.php
120 lines (92 loc) · 2.72 KB
/
for.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
fwrite(STDOUT, PHP_EOL . 'INPUT START NUMBER' . PHP_EOL);
$start = trim(fgets(STDIN));
while (!is_numeric($start)) {
fwrite(STDOUT, PHP_EOL . 'ERROR -- NEED NUMBER' . PHP_EOL);
$start = trim(fgets(STDIN));
}
if ((int) $start != (double) $start) {
fwrite(STDOUT, PHP_EOL . 'FLOAT ACCEPTED -- ROUNDING DOWN');
}
$start = (int) $start;
fwrite(STDOUT, PHP_EOL . 'INPUT END NUMBER' . PHP_EOL);
$end = trim(fgets(STDIN));
while (!is_numeric($end)) {
fwrite(STDOUT, PHP_EOL . 'ERROR -- NEED NUMBER' . PHP_EOL);
$end = trim(fgets(STDIN));
}
if ((int) $end != (double) $end) {
fwrite(STDOUT, PHP_EOL . 'FLOAT ACCEPTED -- ROUNDING DOWN');
}
$end = (int) $end;
fwrite(STDOUT, PHP_EOL . 'INPUT INCREMENT OR LEAVE BLANK FOR DEFAULT' . PHP_EOL);
$increment = trim(fgets(STDIN));
if ((int) $increment != (double) $increment) {
fwrite(STDOUT, PHP_EOL . 'FLOAT ACCEPTED -- ROUNDING DOWN');
$increment = (int) $increment;
}
$ok = false;
while(!$ok) {
if ($increment === '') {
$increment = 1;
}
// why does adding '$increment != 0 and ' to the beginning of this conditional break it?
while ((!is_numeric($increment) or ($increment < 0 and $start < $end) or ($increment > 0 and $start > $end) or $increment == 0)) {
if (!is_numeric($increment)) {
$error = 'NEED NUMBER';
} elseif ($increment < 0) {
$error = 'MUST BE GREATER THAN ZERO';
} elseif ($increment > 0) {
$error = 'MUST BE LESS THAN ZERO';
} elseif ($increment == 0) {
$error = 'MUST NOT BE ZERO';
}
fwrite(STDOUT, PHP_EOL . 'ERROR -- ' . $error . PHP_EOL);
$increment = trim(fgets(STDIN));
if ((int) $increment != (double) $increment) {
fwrite(STDOUT, 'FLOAT ACCEPTED -- ROUNDING DOWN');
$increment = (int) $increment;
}
if ($increment === '') {
$increment = 1;
}
}
$increment = (int) $increment;
if (($end - $start) % $increment != 0) {
fwrite(STDOUT, PHP_EOL . 'MAY NOT REACH END - OK?' . PHP_EOL);
$consent = '';
while ($consent !== 'Y' and $consent !== 'YES' and $consent !== 'N' and $consent !== 'NO') {
fwrite(STDOUT, '(Y/N)' . PHP_EOL);
$consent = strtoupper(trim(fgets(STDIN)));
if ($consent === 'Y' or $consent === 'YES') {
$ok = true;
} else {
fwrite(STDOUT, PHP_EOL . 'INPUT INCREMENT OR LEAVE BLANK FOR DEFAULT' . PHP_EOL);
$increment = trim(fgets(STDIN));
}
}
} else {
$ok = true;
}
}
for ($i = $start, fwrite(STDOUT, PHP_EOL . 'BEGINNING PROCESS' . PHP_EOL); $i <= $end; $i += $increment) {
fwrite(STDOUT, $i . PHP_EOL);
}
fwrite(STDOUT, 'ALL DONE' . PHP_EOL);
exit(0);
// echo ((1.4 - 1.2) / .1);
//
// ** this returns 2 **
//
//
// $double = ((1.4 - 1.2) / .1);
// var_dump($double);
//
// ** this returns double(2) **
//
//
// var_dump((int) $double);
//
// ** this returns int(1)**
//
// Why?