Author |
Message |
princess
|
Posted: Thu May 29, 2003 10:26 pm Post subject: my bank machine doesn't work... |
|
|
ya well my bank machine doesn't work and i don't know why... i think it might be the getch.. put still i don't understand what i am doing wrong... can someone help me
code: |
var balance : real %globel variable
var font1, font2 : int
balance := 1000 %assigning variable a value
font1 := Font.New ("Lucida Console:32:Bold")
font2 := Font.New ("Lucida Console:14")
procedure Deposit %start of procedure
var deposit : real %declaring all variables
put "DEPOSITS" %Title of the procedure
put ""
put ""
put "Enter amount of deposit: " .. %Asking for user input
get deposit %user input
balance := balance + deposit %adding deposit to the balance
put "Current balance: $", balance %outputing the new balance
end Deposit %end of procedure
procedure Withdrawal %start of the procedure
var withdrawal : real %decalre all variables
put "WITHDRAWALS" %tile fo the procedure
put ""
put ""
put "Enter amount of withdrawal: " .. %asking for user input
get withdrawal %user input
if withdrawal <= balance then
%start of the outer if statement-only condition
if withdrawal rem 10 = 0 then
%start of the innter if statement-first condition
balance := balance - withdrawal
%takes amount of money out of the withdrawal
else %for the error message
put "Invaild amount(most be a multiple of 10)"
end if
else %if the balance is less than withdrawal
put "Insufficient Funds"
end if %end of the if statements
put "Current balance: $", balance : 0 : 2
%displays balance after withdrawal
end Withdrawal %end of procedure
procedure FastCash
var opt : int
loop
cls
put "FAST CASH"
put ""
put "Choose an option"
put "1.) $10"
put "2.) $20"
put "3.) $40"
put "4.) $80"
put "5.) $100"
put "6.) Cancel"
put "Your choice: " ..
get opt
if opt = 1 then
if balance < 10 then
put "Insufficient Funds"
delay (2000)
else
balance := balance - 10
exit when opt = 1
end if
elsif opt = 2 then
if balance < 20 then
put "Insufficient Funds"
delay (2000)
else
balance := balance - 20
exit when opt = 2
end if
elsif opt = 3 then
if balance < 40 then
put "Insufficient Funds"
delay (2000)
else
balance := balance - 40
exit when opt = 3
end if
elsif opt = 4 then
if balance < 80 then
put "Insufficient Funds"
delay (2000)
else
balance := balance - 80
exit when opt = 4
end if
elsif opt = 5 then
if balance < 100 then
put "Insufficient Funds"
delay (2000)
else
balance := balance - 100
exit when opt = 5
end if
elsif opt = 6 then
put "Cancelled"
exit when opt = 6
else
put "Invaild Option"
delay (2000)
cls
end if
end loop
put "Current Balance: ", balance : 0 : 2
end FastCash
procedure Balance
put "Your Current Balance: $", balance
end Balance
procedure Main
var s : string (1)
put "How may I help you?"
put ""
put "1. Deposit"
put "2. Withdrawal"
put "3. Fast Cash"
put "4. Balance"
put "5. Exit"
get s
loop
if s = "1" then
getch (s)
Deposit
elsif s = "2" then
getch (s)
Withdrawal
elsif s = "3" then
getch (s)
FastCash
elsif s = "4" then
getch (s)
Balance
elsif s = "5" then
put ""
put ""
put "Thank You & Good-Bye"
exit when s = "5"
else
put ""
put "Invaild Option"
end if
end loop
end Main
setscreen ("graphics:800;600")
Main
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
krishon
|
Posted: Fri May 30, 2003 8:49 am Post subject: (No subject) |
|
|
i'm going to make it simpler, but do u know aobut case statements? |
|
|
|
|
![](images/spacer.gif) |
tum_twish
|
Posted: Fri May 30, 2003 10:30 am Post subject: (No subject) |
|
|
remove all getches
you r asking for something y dont need |
|
|
|
|
![](images/spacer.gif) |
krishon
|
Posted: Fri May 30, 2003 2:32 pm Post subject: (No subject) |
|
|
ye, i wouldn't use procedures, it'll help if u use case statements, with a menu before it and a loop around everything so that you can actually exit. |
|
|
|
|
![](images/spacer.gif) |
ThunderChuncky
![](http://yamatonadeshico.jp/)
|
Posted: Fri May 30, 2003 2:43 pm Post subject: (No subject) |
|
|
Also, put the loop above the variable in the main program. |
|
|
|
|
![](images/spacer.gif) |
ThunderChuncky
![](http://yamatonadeshico.jp/)
|
Posted: Fri May 30, 2003 2:46 pm Post subject: (No subject) |
|
|
I made a mistake and submitted the same message twice. what I really mean to say is after this one. |
|
|
|
|
![](images/spacer.gif) |
ThunderChuncky
![](http://yamatonadeshico.jp/)
|
Posted: Fri May 30, 2003 2:50 pm Post subject: (No subject) |
|
|
A delay and a cls at the end of the loop woudn't hurt either. After that you should be fine. |
|
|
|
|
![](images/spacer.gif) |
princess
|
Posted: Fri May 30, 2003 9:55 pm Post subject: (No subject) |
|
|
Thank u everyone... it now works.... thanx |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|