I just want to execute findSum() function when '+' key is pressed. so when I press '+' key, then the function findSum() must be called. This is my program so far:
numberOfInput = 0
sum = 0
io.write('\t', "Welcome to My Calculator", '\n')
repeat
io.write("for addition, press '+' :", '\n')
findSumSection = io.read()
until
(string.match(findSumSection, '+'))
function findSum()
io.write("Enter the amount of feed(s):",'\n')
numberOfInput = io.read()
x = numberOfInput
for i = 1, x, 1 do
io.write('\n',"enter the number: ")
inputs = io.read()
sum = sum + inputs
end
return sum
end
io.write('\n',"The Sum of your feeds is:", '\n' , findSum(), '\n')
io.write("Do you want to continue? [Y/N]")
inputYesorNo = io.read()
if (string.match(inputYesorNo, 'yes')) then
print("Starting the program again")
else if(string.match(inputYesorNo, 'no')) then
os.exit()
else
print("The program can not understand the procedure")
end
end