%********************************************************************
% Jordan Dykstra *
% April 16 *
% This program allows the user to order a candy bar and recieve *
% change as required *
%********************************************************************
%***********************************
% Variables
var money : int % The ammount of money put into the machine
var change : int % The remaining change
var total : int % The total cost of the item
var item : string (1) % The item (getch'ed from user)
var twent : int := 2000 %*\
var ten : int := 1000 %****\
var five : int := 500 %*****\
var toon : int := 200 %******\
var loon : int := 100 %*******\ setting the value of coins
var quart : int := 25 %*******/ Like the fancy slashes???
var dime : int := 10 %*******/
var nick : int := 5 %*******/
var penn : int := 1 %******/
var totaltwent : int %\
var totalten : int %*\
var totalfive : int %*\
var totaltoon : int %**\
var totalloon : int %***\
var totalquart : int %***\ The number of coins
var totaldime : int %****/
var totalnick : int %***/
var totalpenn : real %*/
%music
process PlayMusic
Music.PlayFile ("cd")
end PlayMusic
% Picture loading...
Pic.ScreenLoad ("coffeecrisp.jpg", 100, 275, picCopy)
Pic.ScreenLoad ("caramilk.jpg", 100, 198, picCopy)
Pic.ScreenLoad ("rolo.jpg", 100, 50, picCopy)
Pic.ScreenLoad ("skittles.jpg", 300, 275, picCopy)
Pic.ScreenLoad ("smarties.jpg", 300, 198, picCopy)
Pic.ScreenLoad ("wonkabar.jpg", 320, 50, picCopy)
%*****************************************
%Draw a box to outline machine
Draw.Line (100, 350, 500, 350, green)
Draw.Line (100, 50, 100, 350, green)
Draw.Line (500, 50, 500, 350, green)
Draw.Line (100, 50, 500, 50, green)
%*****************************************
%*****************************************
% Calculate cost of item *
%*****************************************
setscreen ("nocursor")
color (brightgreen)
put " "..
put "Enter Item code"
loop
getch (item)
if item = "a" then
total := 125
elsif item = "b" then
total := 150
elsif item = "c" then
total := 75
elsif item = "d" then
total := 175
elsif item = "e" then
total := 250
elsif item = "f" then
total := 225
else
put "Invalid option. "
end if
exit when item = "a"
exit when item = "b"
exit when item = "c"
exit when item = "d"
exit when item = "e"
exit when item = "f"
end loop
%*****************************************
% This is the problem picture
Pic.ScreenLoad ("vendingmachine.jpg", 50, 100, picCopy)
setscreen ("nocursor")
color (brightgreen)
cls
put " "..
put "please insert coin or bill"
put " "..
put "Only coins or bills in the denominations of"
put " "..
put "1, 2, 5, 10, and 20 are accepted."
get money
money := money * 100
change := money - total
totaltwent := change div twent
change := change mod twent
totalten := change div ten
change := change mod ten
totalfive := change div five
change := change mod five
totaltoon := change div toon
change := change mod toon
totalloon := change div loon
change := change mod loon
totalquart := change div quart
change := change mod quart
totaldime := change div dime
change := change mod dime
totalnick := change div nick
change := change mod nick
totalpenn := change
put "Your change is:"
if totaltwent > 0 then
put totaltwent, " twenties"
end if
if totalten > 0 then
put totalten, " tens"
end if
if totalfive > 0 then
put totalfive, " fives"
end if
if totaltoon > 0 then
put totaltoon, " toonies"
end if
if totalloon > 0 then
put totalloon, " loonies"
end if
if totalquart > 0 then
put totalquart, " quarters"
end if
if totaldime > 0 then
put totaldime, " dimes"
end if
if totalnick > 0 then
put totalnick, " nickels"
end if
if totalpenn > 0 then
put totalpenn, " pennies"
end if
fork PlayMusic
|