1

I just started trying to have a gas law code for chemistry today. I don't really understand the syntax of TI basic. It will run after the first If statement. Even if the numbers entered only pertains to the first if statement, it will still have a syntax error immediately after it calculates the answer for the first statement. Thanks!

Input "Temp(k):",T
Input "Pressure(atm):",P
Input "Volume(L):",V
Input "mol:",N

If T=0
Then
(P*V)/(N*0.0821)→T
Disp "Temp(k):",T

If P→0 
Then 
(N*0.0821*T)/V→P
Disp "Pressure(atm)":,P


If V→0 
Then
(N*0.0821*T)/P→V
Disp "Volume(L):",V


If N→0 
Then
(P*V)/(0.0821*T)→N
Disp "mol:",N
ankh-morpork
  • 1,732
  • 1
  • 19
  • 28
Max Yuan
  • 121
  • 1
  • 1
  • 6

6 Answers6

2
If P→0

?

I think that should be If P=0 (and ditto for the next two if statements as well).

The operator is assignment, as in (P*V)/(N*0.0821)→T places the value of (P*V)/(N*0.0821) into T. On the other hand, = is the comparison operator.

In addition, I thought (though this is stretching my memory a bit) that the then variant of if was required to have a end as well.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
2

The problem is that you are confusing the assignment operator with the equal operator. The equal operator which is the equal sign that shows equality with the assignment operator (-->) that stores the value on the left side in the variable on the right. You wanted to show equality so you should have used = instead of -->.

Additionally, if you have more than one operation in an if-then statement block you have to close it with the 'END' operation.

Chris
  • 6,914
  • 5
  • 54
  • 80
1
  1. It should be P=0, not P→0. (Though that may have been a typo)

  2. If statements have to be followed by a closing End command, which denotes the end of the If block.

user3932000
  • 671
  • 8
  • 24
1

Since you are using TI-83/84 BASIC, here is correct code for you.

"Temp(k):→Str1
"Pressure(atm):→Str2
"Volume(L):→Str3
Input Str1,T
Input Str2,P
Input Str3,V
Input "mol:",N
If not(T
Then
PV/(N.0821→T
Disp Str1,T
End
If not(P
Then 
N.0821T/V→P
Disp Str2,P
End
If not(V
Then
N.0821T/P→V
Disp Str3,V
End
If not(N
Then
PV/(.0821T→N
Disp "mol:",N
End
Timtech
  • 1,224
  • 2
  • 19
  • 30
0

Besides paxdiablo's answer, I believe the Thens should be on the same line as the Ifs and each If needs an accompanying EndIf statement to end the block it should execute.

Like so:

If T=0 Then
 (P*V)/(N*0.0821)→T
 Disp "Temp(k):",T
EndIf

If P=0 Then 
 (N*0.0821*T)/V→P
 Disp "Pressure(atm)":,P
EndIf

If V=0 Then
 (N*0.0821*T)/P→V
 Disp "Volume(L):",V
EndIf

If N=0 Then
 (P*V)/(0.0821*T)→N
 Disp "mol:",N
EndIf
PGmath
  • 381
  • 3
  • 16
0

The only thing that needs to be added is an End statement at the end. Also, the If statement needs to be changed.

If T≠0
Then
(P*V)/(N*0.0821)→T
Disp "Temp(k):",T
End
Richard Chase
  • 71
  • 1
  • 2