-
-
Save RayMPerry/61f7a2efb5f864dc9ad8853ce147e984 to your computer and use it in GitHub Desktop.
Tip Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
subset DollarAmount of Cool where * ~~ ^<[0 .. 9\.]>+$; | |
subset Percentage of DollarAmount where * > 1; | |
my $bill-amount; | |
my $tax-percentage; | |
repeat { | |
$bill-amount = prompt "What is the bill amount? " | |
} until DollarAmount($bill-amount) !~~ Failure; | |
repeat { | |
$tax-percentage = prompt "What is the tip percentage? " | |
} until Percentage($tax-percentage) !~~ Failure; | |
my $tip-amount = ($bill-amount * ($tax-percentage / 100)).round: 0.01; | |
say "The tip amount is \$$tip-amount."; | |
say "The total amount is \$", $bill-amount + $tip-amount, "."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works: