Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use v5.22.0; # sub routine signatures requires perl >= 5.22
- use feature qw(say);
- use strict;
- use warnings;
- use experimental qw(signatures);
- my @category_prices = (
- "Office Visit" => 75.0,
- "Vaccination" => 50.0,
- "Hospitalization" => 300.5,
- "Heartworm Treatment" => 150.5,
- "Overnight Stay" => 450.0,
- "Dentistry" => 200.5,
- "X-Ray" => 275.0,
- "Lab Work" => 45.0,
- "Prescription" => 15.5,
- );
- sub calculate_total($cost, $total) { $cost+$total }
- sub amount_due($total) {
- my $sales_tax = 0.07 * $total;
- $total += $sales_tax;
- say "Amount Due (inc. of sales tax) ", $total;
- say "Thank you for your visit bark bark! (❍ᴥ❍ʋ)~ Clearing for next customer.";
- }
- sub print_menu($total) {
- say "Welcome to 'Lions Tigers and Bears' Pet Clinic! ฅ^•ﻌ•^ฅ ~(=^‥^)";
- say "Press the adjacent number to add the the service to your bill! meow~";
- say "SERVICE PRICE";
- my $num_categories = ($#category_prices+1)/2;
- my @categories = map { $category_prices[$_*2] } 0..($num_categories-1);
- my @prices = map { $category_prices[$_*2 +1] } 0..($num_categories-1);
- my %prices = map { $categories[$_] => $prices[$_] } 0..($num_categories-1);
- my %choices = map { ($_+ 1 ) => $categories[$_] } 0..($num_categories-1);
- for my $i (0..$#categories) {
- my $idx = $i+1;
- my $price = format_price($prices[$i]);
- say "$idx: $categories[$i]\t$price";
- }
- say <<'END';
- 0: Check Out 0
- Type 30 to Terminate 0
- END
- my $choice = -1;
- my $cost = 0.0;
- my @bill;
- prompt();
- while (my $choice = <>) {
- next if !defined $choice;
- if ( $choice !~ /^\d+$/) {
- say "\tPlease type an integer.";
- prompt();
- next;
- }
- $choice = int $choice;
- exit if $choice == 30;
- last if $choice == 0;
- if (!exists $choices{$choice}) {
- say "\tIgnoring unrecognized command '$choice'";
- prompt();
- next;
- }
- my $category = $choices{$choice};
- my $price = $prices{$category};
- push @bill, [$category, $price];
- $total = calculate_total($price, $total);
- say "";
- say "Items on your bill";
- for my $item ( @bill ) {
- my ( $category, $price ) = @$item;
- $price = format_price($price);
- say "$category \t\$$price";
- }
- say "";
- say "Total \$$total";
- prompt();
- }
- amount_due($total);
- return $total;
- }
- sub format_price($price) { sprintf "%.1f", $price }
- sub prompt { print "> " }
- my $total = 0;
- while (1) {
- $total = print_menu($total);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement