
-----------------------------------
Lundale34
Fri May 18, 2012 1:05 pm

Bank Machine program
-----------------------------------
What is it you are trying to achieve?
I need my program to take out money in intervals of 20's up to 500. It will crash when anything but an interval of 20 or over 500 is inputted, it will also allow the program to take out more than the current balance.


What is the problem you are having?



Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)








Please specify what version of Turing you are using


-----------------------------------
Tony
Fri May 18, 2012 3:39 pm

Re: Bank Machine program
-----------------------------------

Describe what you have tried to solve this problem

Clearly not. Have you tried [tdoc]mod[/tdoc]?

-----------------------------------
Lundale34
Sat May 19, 2012 11:15 am

RE:Bank Machine program
-----------------------------------
Yes I have, I have a function that I thought I attached as well. 

function makeWithdraw (balance : real, var amountWithdrawn : real) : real
    var newBalance : real
    drawfillbox (0, 0, 500, 200, blue)
    locate (20, 20)
    
    if amountWithdrawn mod 20 = 0 and amountWithdrawn  500 then
    colour (white)    
    put "Insufficient Funds"
    colour (blue)
        end if
end makeWithdraw

-----------------------------------
Aange10
Sat May 19, 2012 8:31 pm

RE:Bank Machine program
-----------------------------------
From running the program it seems like your problem is here:


function makeWithdraw (balance : real, var amountWithdrawn : real) : real
    var newBalance : real
    drawfillbox (0, 0, 500, 200, blue)
    locate (20, 20)
    if amountWithdrawn mod 20 = 0 then
        put "You have withdrawn $", amountWithdrawn
        result
            balance - amountWithdrawn
    else
        put "Insufficient Funds"
    end if
end makeWithdraw



The error message is "Function failed to give result". Try adding a result even if you didn't withdraw how much they asked. If you didn't withdraw anything, the result of the transaction would be the same as the balance before it. Also, the else clause's 'put' statement is incorrect, it's not insufficient funds, it's that the funds aren't incremented in twenty.

-----------------------------------
Lundale34
Mon May 21, 2012 10:15 am

RE:Bank Machine program
-----------------------------------
I fixed the over 500 problem, but still have had no luck with the increments of 20. 

The function is now
 balance then
    colour (white)
    put "Insufficient Funds"
    result balance
    end if
end makeWithdraw>

-----------------------------------
mirhagk
Mon May 21, 2012 12:04 pm

RE:Bank Machine program
-----------------------------------
You need another else that gets run when amountWithdrawn mod 20 is not 0. It needs to have a result balance. In fact you could just move the result balance from the other 2 elsif blocks to the end of the function (after the end if). That will make it so that as long as one of the if statements doesn't return anything, it returns their balance.

-----------------------------------
evildaddy911
Mon May 21, 2012 12:30 pm

RE:Bank Machine program
-----------------------------------
if you know [even extremely basic] buttons, then make some for each value that you can withdraw

-----------------------------------
Raknarg
Mon May 21, 2012 2:56 pm

RE:Bank Machine program
-----------------------------------
@evildaddy he needs the basics down before he adds anything nice to it.

-----------------------------------
evildaddy911
Mon May 21, 2012 3:24 pm

RE:Bank Machine program
-----------------------------------
well, it seems that the problem has to do with dummy-proofing, and dummy-proofing is much easier without text input...

if amountWithdrawn mod 20 = 0 and amountWithdrawn 