This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
nateracecar5's profile picture

Help with a VERY special program

Started by nateracecar5, 07 October 2012 - 11:32 PM
nateracecar5 #1
Posted 08 October 2012 - 01: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!

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
lieudusty #2
Posted 08 October 2012 - 01:38 AM
You would need to do a while true loop
remiX #3
Posted 08 October 2012 - 01: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
hego555 #4
Posted 08 October 2012 - 06: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!