Jump to content




Help with a VERY special program


  • You cannot reply to this topic
3 replies to this topic

#1 nateracecar5

  • Members
  • 94 posts

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!
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


#2 lieudusty

  • Members
  • 419 posts

Posted 08 October 2012 - 12:38 AM

You would need to do a while true loop

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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 hego555

  • Members
  • 89 posts

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!





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users