 Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
Typical Cashiers Problem (Involving Trucks/Weight)        Author Message
vexd  Posted: Mon Sep 29, 2003 6:36 pm   Post subject: Typical Cashiers Problem (Involving Trucks/Weight)

%**********************************************************************************
%* Author: VeXD *
%* Date: Sept, 24 2003 *
%* Purpose:To make a program that can solve the classical cashier's problem. *
%* Input: An integer (weight) of the package *
%* Output: An integer of how many weights can go on the truck. *
%**********************************************************************************

var intWeight : int
var intPackage : int := 0
var strYesNo : string (1)

put "What is the capacity of the truck?"
get intWeight

loop
exit when intWeight > 0
put "Please Enter a valid capacity of the truck:"
get intWeight
end loop
intPackage := intWeight

loop
intPackage := intWeight div 500
if intPackage not= 0 then
intWeight := intWeight mod 500
if intPackage > 1 then
put intPackage, " - 500's"
elsif intPackage = 1 then
put intPackage, " - 500"
end if
end if
intPackage := intWeight div 100
if intPackage not= 0 then
intWeight := intWeight mod 100
if intPackage > 1 then
put intPackage, " - 100's"
elsif intPackage = 1 then
put intPackage, " - 100"
end if
end if
intPackage := intWeight div 50
if intPackage not= 0 then
intWeight := intWeight mod 50
if intPackage > 1 then
put intPackage, " - 5's"
elsif intPackage = 1 then
put intPackage, " - 50"
end if
end if
intPackage := intWeight div 20
if intPackage not= 0 then
intWeight := intWeight mod 20
if intPackage > 1 then
put intPackage, " - 20's"
elsif intPackage = 1 then
put intPackage, " - 20"
end if
end if
intPackage := intWeight div 10
if intPackage not= 0 then
intWeight := intWeight mod 10
if intPackage > 1 then
put intPackage, " - 10's"
elsif intPackage = 1 then
put intPackage, " - 10"
end if
end if
intPackage := intWeight div 5
if intPackage not= 0 then
intWeight := intWeight mod 5
if intPackage > 1 then
put intPackage, " - 5's"
elsif intPackage = 1 then
put intPackage, " - 5"
end if
end if
intPackage := intWeight div 2
if intPackage not= 0 then
intWeight := intWeight mod 2
if intPackage > 1 then
put intPackage, " - 2's"
elsif intPackage = 1 then
put intPackage, " - 2"
end if
end if
if intWeight = 1 then
put intWeight, " - 1"
end if
put "----------------"
put "Calculate another capacity? y/n"
getch (strYesNo)
exit when strYesNo = "n" or strYesNo = "N"
put "\nWhat is the capacity of the truck?"
get intWeight
intPackage := intWeight
cls
end loop             