As my first real program in Lua, I'd like to create a molecular weight calculator (similar to the one here: http://www.lenntech.com/calculators/molecular/molecular-weight-calculator.htm )
I'd like some help with the first step of this program. My first step should be take the users input as a string, and than to split the string. I am looking at http://lua-users.org/wiki/StringLibraryTutorial and trying to figure out how to do this. When the user input is CH4 the program should split this string into C
, and H4
. Here is my code:
H = 1.008
C = 12.011
N = 14.007
O = 15.999
io.write("Enter molecular formula")
input = io.read()
result =
print("the molecular weigth is" .. result)
Can someone show me how I can accept the user input as a string and how to split that string?
Edit: as requested, I have been more specific in my exact question