Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Typical Cashiers Problem (Involving Trucks/Weight)
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
vexd




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: