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

Username:   Password: 
 RegisterRegister   
 Exiting a loop with mod
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
BigBear




PostPosted: Tue Feb 05, 2008 10:56 am   Post subject: Exiting a loop with mod

I have a program that return the correct change but for some reason it stays in a loop untill user ends program.
code:
            loop
                if change1 > 1000 then
                    put "\nPlease call your manager."
                elsif change1 > 20 then
                    put "$20 bill(s): ", change1 div 20
                    change1 := change1 mod 20
                elsif change1 = 20 then
                    put "$20 bill(s): ", change1 div 20
                    change1 := change1 mod 20
                elsif change1 < 20 and change1 >= 10 then
                    put "$10 bill(s): ", change1 div 10
                    change1 := change1 mod 10
                elsif change1 < 10 and change1 >= 5 then
                    put "$5 bill(s): ", change1 div 5
                    change1 := change1 mod 5
                elsif change1 < 5 and change1 >= 2 then
                    put "$2 coins(s): ", change1 div 2
                    change1 := change1 mod 2
                elsif change1 < 2 and change1 >= 1 then
                    put "$1 coins(s): ", change1 div 1
                    change1 := change1 mod 1
                elsif change1 < 1 and change1 >= 0.25 then
                    put "$0.25 coin(s): ", change1 div 0.25
                    change1 := change1 mod 0.25
                elsif change1 < .25 and change1 >= 0.10 then
                    put "$0.10 coin(s): ", change1 div 0.10
                    change1 := change1 mod 0.10
                elsif change1 < .10 and change1 >= 0.05 then
                    put "$0.05 coin(s): ", change1 div 0.05
                    change1 := change1 mod 0.05
                elsif change1 < .05 and change1 >= 0.01 then
                    put "$0.01 coin(s): ", change1 div 0.01
                    change1 := change1 mod 0.01
                elsif change1 = 0.01 then
                    put "$0.01 coin(s): ", change1 div 0.01
                    change1 := change1 mod 0.01
                elsif change < 0.01 then
                    change := 0
                end if
                exit when change1 = 0 or change1 > 1000
            end loop



CashMachine.zip
 Description:
Zip file of all files

Download
 Filename:  CashMachine.zip
 Filesize:  4.68 KB
 Downloaded:  65 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
BigBear




PostPosted: Wed Feb 06, 2008 10:56 am   Post subject: Re: Exiting a loop with mod

Anyone?
OneOffDriveByPoster




PostPosted: Wed Feb 06, 2008 11:21 am   Post subject: Re: Exiting a loop with mod

From the part you pasted in; you have a "change" and a "change1"... Not sure if that is the problem.
BigBear




PostPosted: Tue Feb 12, 2008 1:55 am   Post subject: Re: Exiting a loop with mod

Yes that was just a bad copy paste but nope not the problem. I was wondering if it is my comp that is having the problem can some one run this and tell me if it works?
HeavenAgain




PostPosted: Tue Feb 12, 2008 2:13 am   Post subject: RE:Exiting a loop with mod

code:
int array[] bills = {20, 10, 5}
real array[] coins = {2 , 1, 0.25, 0.1, 0.01}
if change > 1000 then
 put "call 911"
end if
for i : 0..bills.length
int temp := change div bills[i]
 if (temp not = 0) then
  put "$", bills[i], "bills: ", temp
  change -= (temp*bills[i])
 end if
end for
for i : 0..coins.length
int temp := change div coins[i]
 if (temp not = 0) then
  put "$", coins[i], "coins: ", temp
  change -= (temp*coins[i])
 end if
end for
Rolling Eyes mod is not necessary..... just makes it confusing, think for clarity, simple and stupid is the best way to solve things
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: