-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWoodworking Program
107 lines (96 loc) · 3.18 KB
/
Woodworking Program
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
## Assignment: Project 2
## Author: Nicolas Sims ([email protected])
## Version: 09.29.2014.01
## Purpose: Create an application to compute the price of a sign a customer orders, based on multiple factors.
use 5.14.1;
use warnings;
my ($orderNumber, $numberCharacters, $totalBill, $colorCharacters, $woodType, $errorCounter);
my ($customerName);
sub main {
setOrderNumber();
setCustomerName();
setWoodType();
setNumberCharacters();
setColorCharacters();
setTotalBill();
}
main();
sub setOrderNumber {
if (!(defined $orderNumber)) {
print "\nEnter order number. ";
chomp ($orderNumber = <STDIN>);
}
}
sub setCustomerName {
if (!(defined $customerName)) {
print "\nEnter the customer's name. ";
chomp ($customerName = <STDIN>);
}
}
sub setWoodType {
if (!(defined $woodType) || $woodType != 1 && $woodType != 2) {
print "\nEnter the type of wood the customer wants his sign to be made of. \n(Oak = 1, Pine = 2) ";
chomp ($woodType = <STDIN>);
if ($woodType != 1 && $woodType != 2) {
errorHandler();
}
}
}
sub setNumberCharacters {
if (!(defined $numberCharacters) || $numberCharacters == 0) {
print "\nEnter the number of characters the customer wants on his sign. ";
chomp ($numberCharacters = <STDIN>);
if ($numberCharacters == 0) {
errorHandler();
}
}
}
sub setColorCharacters {
if (!(defined $colorCharacters) || $colorCharacters != 1 && $colorCharacters != 2 && $colorCharacters != 3) {
print "\nEnter the color of the characters the customer wants on his sign.\n(Black = 1, White = 2, Goldleaf = 3) ";
chomp ($colorCharacters = <STDIN>);
if ($colorCharacters != 1 && $colorCharacters != 2 && $colorCharacters != 3) {
errorHandler();
}
}
}
sub setTotalBill {
use constant MINIMUM_CHARGE => 30;
use constant OAK_CHARGE => 15;
use constant CHARACTER_CHARGE => 3;
use constant GOLDLEAF_CHARGE => 12;
if ($woodType == 1) {
$totalBill = MINIMUM_CHARGE + OAK_CHARGE;
if ($numberCharacters > 6) {
$totalBill = $totalBill + ($numberCharacters - 6) * CHARACTER_CHARGE;
}
if ($colorCharacters == 3) {
$totalBill = $totalBill + 12;
}
} else {
$totalBill = MINIMUM_CHARGE;
if ($numberCharacters > 6) {
$totalBill = $totalBill + ($numberCharacters - 6) * CHARACTER_CHARGE;
}
if ($colorCharacters == 3) {
$totalBill = $totalBill + 12;
}
}
system("cls");
print "\nThe total bill for $customerName will be \$$totalBill. Their order number is $orderNumber. \n";
}
sub errorHandler {
print "\nYou've entered something wrong. Try again. ";
if (!(defined $errorCounter)) {
$errorCounter = 0
}
$errorCounter = $errorCounter + 1;
if ($errorCounter == 5) {
system("cls");
print "\nYou're drunk. Stop using the computer. \n\n\n\n";
sleep 2;
system("cls");
die;
}
main ();
}