As my first contribution to this forum, I'd like to share my first problems I solved. I wonder if there are other solutions, so please comment. As part of a bigger program (Maths Trainer, doing fast arithmetic in your head, timed with highscore,etc) I need two random numbers as described in summary. You know those Mathemagic tricks…for numbers like 23×27, 68x62 or 42×48, you simply do the following. e.g. 46×44. Multiply 40×(40+10) add (6×4). Voila, you get 2024 within seconds in your head. The programm generates first one random number. Divide it by 10. I assign a variable to each for iPart() and fPart(). The iPart() is multiplied by 10 and added to fPart() which was first subtracted from 1 and muliplied by 10. Her is an example.
1. random number generated is 73 (so I need another which is 77)
2. divide 73 by 10 and assign to variable. A=7.3
3. B=ipart(A) giving me 7
4. C=fpart(A) giving me 0.3
5. B×10=70 and (1-C)×10=7 aded to gether giving me 77 assigned to D
6. result is 73 generated from 77
The rest is straight forward. Prompt and check that 77×73 is 5621. I want to add difficulty levels that shortens answer times. Also add highscores, nice UI,etc.
Here is the result so far:
:ClrHome
:Lbl A
:randInt(11,99)->A
:A/10->B
:A/10->C
:fpart(B)->D
:ipart(C)->E
:E×10->F
:(1-D)×10->G
:F+G->H
:A×H->I (fixed mistake pointed out by UEBERhelp)
:Disp A,H
:Prompt J
:If J=I
:Then
:ClrHome
:Output(5,8,"Bravo")
:Goto A
:Else
:ClrHome
:Output(5,8,"Boooo…")
:Goto A
Enjoy!
I am aware I can get rid of some variables and calculate some inside the commands. Also its just spaghetti code. But for the time it works.
In case you know of some more elegant solution to find the second nunber with the given requierments, let me know. I will post final results on my new wiki page.
Have a nice day.
Benarius
…indistinctness is my forte…
J.M.W. Turner