-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplexATM.swift
56 lines (43 loc) · 1.86 KB
/
complexATM.swift
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
// Allen ISD Computer Science Assignment
// Non-sequential Project | complexATM
// Zayam Tariq
// Computer Science I, Period 2
// 2018.01.26
/*
You're responsible for dispensing money from an ATM.
The ATM can only dispense $5 and $20 bills.
The command line will specify the total dollar value to withdraw which must be
divisible by 5.
You must print one line indicating that either a $5 or $20 bill was dispensed
for each bill dispensed.
For example, if the program is invoked as: ./complexATM 75
Your output should be:
$20.00 dispensed
$20.00 dispensed
$20.00 dispensed
$5.00 dispensed
$5.00 dispensed
$5.00 dispensed
Include an assert statement for each assumption that you are making.
*/
// Continue with your code here
func dispenseBills(dollarValue:Int, typeOfBill:Int) -> Int {
let billsToDispense = dollarValue / typeOfBill
var moneyRemaining = dollarValue
for _ in 0 ..< billsToDispense {
print("$\(typeOfBill).00 dispensed")
moneyRemaining -= typeOfBill
}
return moneyRemaining
}
// The following assertions make clear the assumptions that your program is making
assert(CommandLine.arguments.count == 2, "Exactly one argument is required")
assert(Int(CommandLine.arguments[1]) != nil, "Argument must be an integer")
// Read the integer value from the command line.
// Note that we've verified above, via the assertions, that we definitely have an integer argument
let dollarValueRequested = Int(CommandLine.arguments[1])!
assert(dollarValueRequested % 5 == 0, "Dollar value requested must be evenly divisible by $5.00")
var dollarValueRemaining = dollarValueRequested
dollarValueRemaining = dispenseBills(dollarValue: dollarValueRemaining, typeOfBill:100)
dollarValueRemaining = dispenseBills(dollarValue: dollarValueRemaining, typeOfBill:20)
_ = dispenseBills(dollarValue: dollarValueRemaining, typeOfBill:5)