- Ti Basic Molecular Mass Calculator
- 06 Mar 2014 09:50:11 pm
- Last edited by rmast95 on 06 Mar 2014 10:27:31 pm; edited 1 time in total

I am working on a molecular mass calculator that can take just one string as the input. For example, you input H20 and it outputs 18.02. I know someone else has probably made another program that I could download, but I need the practice actually writing code. Currently I am getting an error when I input more more than H into the string, but I do not know what is causing this error. Any help as to why there is an error would be greatly appreciated because I am stuck.

**Code:**```
```

:DCS

"C3C3C3C3C3C3C3C33333333333333333C3C3C3C3C3C3C3C33333333333333333C3C3C3C3C3C3C3C33333333333333333C3C3C3C3C3C3C3C33333333333333333C3C3C3C3C3C3C3C33333333333333333C3C3C3C3C3C3C3C33333333333333333C3C3C3C3C3C3C3C33333333333333333C3C3C3C3C3C3C3C33333333333333333"

ClrHome

0->Z

Input "FORMULA",Str1

1->X

Repeat A=0

inString(Str1,"H",X->A

inString(Str1,"e",X->B

inString(Str1,"f",X->C

X+1->X

If A+1!=B and A!=0

Then

1.01*(expr(sub(Str1,A+1,1->Z

End

If A+1!=C and A!=0

Then

1.01*(expr(sub(Str1,A+1,1->Z

End

End

1->X

Repeat A=0

inString(Str1,"He",X->A

X+1->X

If A!=0

Then

4*(expr(sub(Str1,A+2,1->Z

End

End

1->X

Repeat A=0

inString(Str1,"Li",X->A

X+1->X

If A!=0

Then

6.94*(expr(sub(Str1,A+2,1->Z

End

End

1->X

Repeat A=0

inString(Str1,"Be",X->A

X+1->X

If A!=0

Then

9.01*(expr(sub(Str1,A+2,1->Z

End

End

Disp Z

Pause