money = 100
term.clear()
term.setCursorPos(1,1)
print("---------------")
print("-cash register-")
print("---------------")
write "Type in command: "
input = read()
if input == "Add cash" then
term.clear()
term.setCursorPos(1,1)
print("----------")
print("-Add Cash-")
print("----------")
write "Add Ammount: "
add = read("$")
money = money + add
else
if input == "Check cash" then
term.clear()
term.setCursorPos(1,1)
print("You have this much money.."..money)
sleep(2)
term.clear()
else
if input == "Remove cash" then
term.clear()
term.setCursorPos(1,1)
print("-------------")
print("-Remove cash-")
print("-------------")
write "Subtract Ammount: "
remove = read("$")
money = money - remove
end
end
end
Help with a VERY special program
Started by nateracecar5, Oct 08 2012 12:32 AM
3 replies to this topic
#1
Posted 08 October 2012 - 12:32 AM
I am building a computercraft cash register but I can't figure out how to get the code to loop to the beginning. Someone help!
#2
Posted 08 October 2012 - 12:38 AM
You would need to do a while true loop
#3
Posted 08 October 2012 - 12:58 AM
local money = 100
function clearPrint(string)
term.clear()
term.setCursorPos(1,1)
print(string)
end
while true do
clearPrint("---------------")
print("-cash register-")
print("---------------")
print("Current balance: "..money.."$.")
print("Type a command: [add, check, remove]")
write("> ")
input = read()
if input == "add" then
clearPrint("----------")
print("-Add Cash-")
print("----------")
write "Add Ammount: "
add = read("$")
money = money + add
print("Your new balance: "..money.."$.")
elseif input == "check" then
clearPrint("---------------")
print("-cash checking-")
print("---------------")
print("You currently have: "..money.."$.")
sleep(2)
elseif input == "remove" then
clearPrint("-------------")
print("-Remove cash-")
print("-------------")
write "Subtract Ammount: "
remove = read("$")
money = money - remove
print("Your new balance: "..money.."$.")
else
-- do whatever you want if they enter an incorrect command
end
end
#4
Posted 08 October 2012 - 05:05 AM
I dont know your exact hopes for this... but heres a tip, instead of asking for input like "add" "checK"
use a menu
So they only have to use the arrow keys to navigate!
use a menu
So they only have to use the arrow keys to navigate!
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











