Last month we started programming with x+y=z. Our meager beginning has revealed the complexity of a simple program. By incrementing one Improvement at a time, we can make this program into a piece of professional work. Let’s first make the computer write the problems for us. Load In last month’s program to get started.
The user’s manual explains random numbers and the INTeger function. The INTeger and RND function will enter a value for x and y automatically. Let’s limit the value of x and y to single digit numbers between 0-9. That will ensure a positive answer. Addition and multiplication present no problem.
In subtraction, the subtrahend must be smaller than the minuend. In division, the dividend (x) must be larger than the divisor (y) in order to ensure a positive number and greater than one. The value of the divisor must be entered first so that the value of the dividend can be multiplied by it to give the dividend the proper value. In order to give the RANDom number generator a starting point, type in:
3300 RAND 0
or
3300 RAND
depending upon your computer. Edit line 3300 to lines 3500, 3700, 3900. Type in:
3310 LET x = INT (RND * 10)
This line can be used in addition, subtraction, and multiplication so edit line 3310 to lines 3510 and 3710. Edit line 3310 to read:
3320 LET y = INT (RND * x)
Now y can never be larger than x.
In division, you cannot divide by 0, therefore the dvisor must never be 0. Type:
3910 LET y = INT (RND * 9)+1
The divisor will never be more than one digit or equal to 0. To keep the answer whole, multiply the random number by the divisor. type:
3920 LET x= INT (RND*10)*y
Delete 3390, 3590, 3790, and 3990.
Consider now providing feed back for a wrong answer. If x + y does not equal z, how can the computer tell the student? One simple straight forward solution is to present the problem to the computer to solve. Type:
3410 IF z<>x+y THEN GO TO 3350
Edit this line to 3610, 3810, 4010 changing the + to – to 3810; to / as appropriate.
In lines 3380, 3580, 3780, and 3980, change the “= ?” to “= “;z
To select the option we desire calls for a menu. Type in:
3070 PRINT AT 6,0; "IF YOU WISH TO DO SOME PRACTICE"
3072 PRINT AT 8,3; "IN ADDITION__ TYPE 1"
3074 ON PRINT AT 10,3; " IN SUBTRACTION TYPE 2"
3076 PRINT AT 12,3; " IN MULTIPLICATION TYPE 3"
3078 PRINT AT 14,3; "IN DIVISION_ TYPE 4"
3079 PRINT AT 16,3; "TO EXIT_____ TYPE 5"
3080 PAUSE 0 (OR 4E4)
Now to read INKEY$ functions:
3090 CLS
3100 LET A$=INKEY$
3110 IF A$="1" THEN GO TO 3310
3120 IF A$="2" THEN GO TO 3510
3130 IF A$="3" THEN GO TO 3710
3140 IF A$=*4" THEN GO TO 3910
3150 IF A$="5" THEN STOP
3160 IF A$<>"1" OR A$‹>" 2" OR A$<> "3" OR A$<>"4" OR A$‹>"5" THEN GOTO 3070
Statement 3160 will only permit use of numbers between 1 and 5.
I have deliberately steered clear of using CLS (clear screen) very much for now. The CLS is a very handy command in programming. when ever you need a clean slate to write or draw on, enter a CLS command in the program. Experiment a little.
Next month, we will number our problems, limit our loop to ten problems, give the number out of ten correct, personalize our program and start our logo, smiley face.
Products
Downloadable Media
Image Gallery
Source Code
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.