Skip to content

Commit

Permalink
Merge pull request #236 from mknos/arithmetic-eof
Browse files Browse the repository at this point in the history
arithmetic: terminate on end-of-file
  • Loading branch information
briandfoy authored Sep 10, 2023
2 parents 353ddd4 + 747143d commit 5bea459
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions bin/arithmetic
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ while ($questions < QUESTIONS) {
# Keep trying till we get something that's a number.
LOOP: {
print "$left $operator $right = ";
chomp ($guess = <>);
$guess = <>;
if (!defined($guess)) {
report();
}
chomp $guess;
if ($guess =~ /\D/) {
print "Please type a number.\n";
redo;
Expand All @@ -143,7 +147,7 @@ while ($questions < QUESTIONS) {
$questions ++;
}

$SIG {INT} -> (); # Terminates.
report();

sub report {
my $seconds = time - $start;
Expand Down Expand Up @@ -182,8 +186,8 @@ If B<arithmetic> thinks your answer is not a number, it will
respond with B<Please type a number!> and repeat the exercise.
After 20 questions, B<arithmetic> will tell you how many exercises you
answered correctly, and how much time it took. Interrupting the game
triggers the same reports; the game is then terminated.
answered correctly, and how much time it took.
You can quit at any time by typing the interrupt or end-of-file character.
If you answer an exercise incorrectly, B<arithmetic> will remember the
numbers involved, and favour those over others.
Expand Down Expand Up @@ -216,8 +220,7 @@ The working of B<arithmetic> is not influenced by any environment variables.
=head1 BUGS
This implementation of B<arithmetic> does not respect the end of file
character.
None known.
=head1 REVISION HISTORY
Expand Down

0 comments on commit 5bea459

Please sign in to comment.