Basically I am trying to get my calculator to show Pythagorean and it gives the answer but the work is messed up so lets say a=5 b=? c=7 so I used the pause command every time the variables A, B, C are modified and it shows the right work and numbers are correct but just before the output commands run it's perfectly correct the numbers and then the output command shows a=6 b=11 c=10084638. Right out of the blue and the C variable isn't modified or anything during this I just used the output command to display C. even after the ouput command runs and I check with display and pause the numbers are fine its just output isn't showing the proper data of the variable. Anyone know how to fix this is the code.

Code:
```ClrHome 0→A 0→B 0→C Lbl 1 Menu("Math","Pythagorean",2,"Quit",3) Lbl 2 Menu("Pythagorean","Solve",4,"Help",5,"Back",6) Lbl 4 Disp "a² + b² = c² Prompt A Prompt B Prompt C If B=0 Then A*A→A C*C→C ClrHome Disp A Disp C Pause "" C-A→B ClrHome Disp A Disp C Disp B Pause "" √(B→B √(A→A √(C→C ClrHome Disp A Disp C Disp B Pause "" ClrHome Output(5,9,A Output(5,10," + " Output(5,13,B Output(5,14," = " Output(5,17,C Output(6,12,"B=" Output(6,14,B Pause "" {rest of code}```
davidclue wrote:

Code:
```ClrHome 0→A 0→B 0→C Lbl 1 Menu("Math","Pythagorean",2,"Quit",3) Lbl 2 Menu("Pythagorean","Solve",4,"Help",5,"Back",6) Lbl 4 Disp "a² + b² = c² Prompt A Prompt B Prompt C If B=0 Then A*A→A C*C→C ClrHome Disp A Disp C Pause "" C-A→B ClrHome Disp A Disp C Disp B Pause "" √(B→B √(A→A √(C→C ClrHome Disp A Disp C Disp B Pause "" ClrHome Output(5,9,A Output(5,10," + " Output(5,13,B Output(5,14," = " Output(5,17,C Output(6,12,"B=" Output(6,14,B Pause "" {rest of code}```

There is a few issues...
By using Output, your output overlaps depending on the size of the numbers at hand. I put the whole thing in a string and displayed the entire string (so that nothing overlaps)
Your labels are wonky and will sometimes lead to unknown label errors.
Instead of checking if a variable is 0, you can check If not(var)
Instead of initializing your variables to 0, you can use DelVar var, which doesn't need a newline in between each
When using the Pause command, the argument is optional, so if you are leaving the string empty, you might as well not put it.
A², B² and C² are more legible and smaller than A*A, B*B and C*C.
You should only ever set the variables to their final values, rather than storing intermediate results to your working variables. (Unless you are absolutely trying to golf your code)
Prompt A:Prompt B:Prompt C can be abbreviated to Prompt A,B,C. Disp is similar.

Code:
```ClrHome DelVar ADelVar BDelVar C Lbl 6 Menu("Math","Pythagorean",2,"Quit",3) Lbl 2 Menu("Pythagorean","Solve",4,"Help",5,"Back",6) Lbl 4 Disp "a² + b² = c² Prompt A,B,C ClrHome If not(B Then Disp "A²=",A² Disp "C²=",C² Disp "B=√(C²-A²) toString(C²)+"-"+toString(A² Disp "B=√("+Ans+") Disp "B=√("+toString(expr(Ans))+") expr("√("+Ans→B Pause B Else If not(C Then Disp "A²=",A² Disp "B²=",B² Disp "C=√(A²+B²) toString(A²)+"+"+toString(B² Disp "C=√("+Ans+") Disp "C=√("+toString(expr(Ans))+") expr("√("+Ans→C Pause C Else Disp "B²=",B² Disp "C²=",C² Disp "A=√(C²-B²) toString(C²)+"-"+toString(B² Disp "A=√("+Ans Disp "A=√("+toString(expr(Ans expr("√("+Ans→A Pause A End End ClrHome Output(5,4,toString(A²)+" + "+toString(B²)+" = "+toString(C² Pause Lbl 5 "HELP Lbl 3```

I added my own little twist to the output to make it look a little bit more like you are actually solving the equation, rather than just spitting out numbers left and right.
If you can't use the toString() command, this code becomes wayyy less elegant (and it's already not very elegant to begin with.
I tried optimizing the code for readability, rather than speed or size, because the difference in the 2 latter categories would not outweigh the benefits of readability in this scenario.
Basically I modified your code to my liking I just have one more problem. So whenever it states the answer at the end (a=4, b=5, c=6.4) it shows the missing number like this 6.403124237. So what I want is it to only display in the decimals to the thousandths so it would look like this 4.03

Code:
```ClrHome DelVar ADelVar BDelVar C Lbl 1 Menu("Math Subjects","Pythagorean",2,"Quit",3) Lbl 2 Menu("Pythagorean","Solve",4,"Help",5,"Back",6) Lbl 4 Disp "a² + b² = c² Prompt A,B,C ClrHome If not(B Then Output(4,8,"a² + b² = c²" Output(5,8,"("+toString(A²)+"+b²="+toString(C²)+")" toString(C²)+"-"+toString(A²) Output(6,8,"B=√("+toString(expr(Ans))+")" expr("√("+Ans→B Output(7,8,toString(A)+" + "+toString(B)+" = "+toString(C Pause "" Else If not(C Then Output(4,8,"a² + b² = c²" Output(5,8,"("+toString(A²)+"+"+toString(B²)+"=c²)" toString(A²)+"+"+toString(B²) Output(6,8,"C=√("+toString(expr(Ans))+") expr("√("+Ans→C Output(7,8,toString(A)+" + "+toString(B)+" = "+toString(C Pause "" Else If not(A Then Output(4,8,"a² + b² = c²" Output(5,8,"(a²+"+toString(B²)+"="+toString(C²)+")" toString(C²)+"-"+toString(B²) Output(6,8,"A=√("+toString(expr(Ans))+")" expr("√("+Ans→A Output(7,8,toString(A)+" + "+toString(B)+" = "+toString(C Pause "" End End End```
You can change the number of displayed decimal digits with the Fix command, e.g. Fix 3 would display π as 3.142.
jacobly wrote:
You can change the number of displayed decimal digits with the Fix command, e.g. Fix 3 would display π as 3.142.

Does not work well due to when it is in Fix 3 the other numbers are affected so the screen appears (a=4.000, b=5.000, c=6.403). I want only the missing number that it's solving for to show to the thousandths.
davidclue wrote:
jacobly wrote:
You can change the number of displayed decimal digits with the Fix command, e.g. Fix 3 would display π as 3.142.

Does not work well due to when it is in Fix 3 the other numbers are affected so the screen appears (a=4.000, b=5.000, c=6.403). I want only the missing number that it's solving for to show to the thousandths.

Then put it in the right place. We are not your personal programmers; you need to use your brain.
MateoConLechuga wrote:
davidclue wrote:
jacobly wrote:
You can change the number of displayed decimal digits with the Fix command, e.g. Fix 3 would display π as 3.142.

Does not work well due to when it is in Fix 3 the other numbers are affected so the screen appears (a=4.000, b=5.000, c=6.403). I want only the missing number that it's solving for to show to the thousandths.

Then put it in the right place. We are not your personal programmers; you need to use your brain.

Code:
`Output(7,8,toString(A)+" + "+toString(B)+" = "+toString(C`

Well I just needed help a bit since I'm beginning I got busy with things and had to take a break so It's not fresh in my mind and I can't position in this line of code so that the Fix command only affects 'toString(C)'

Code:
```toString(A)+" + "+toString(B)+" = "->Str1 Fix 3 Output(7,8,Str1+toString(C```
Use round(, syntax should be round(C,3), iirc
MateoConLechuga wrote:

Code:
```toString(A)+" + "+toString(B)+" = "->Str1 Fix 3 Output(7,8,Str1+toString(C```

Did not know you could store multiple toStrings to 1 String

SM84CE wrote:
Use round(, syntax should be round(C,3), iirc

rounding would work better since for the String command you need to insert a few additional lines to make it work with the Fix command

Edit by moderator: Please use the  button to edit your previous post to avoid posting twice in a row within 24 hours. Thank you.

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum