FRACTIONS AND PERCENTAGES


If you have trouble converting percentages to fractions and vice versa then this is for you.


How to play

The playing instructions are the same as those in the Profit and Loss program which is to be found elsewhere in this book.

Programming hints

The procedure PROC_CALC is a useful procedure converting the computer into a calculator. It could be used on its own if a large number of calculations had to be made and a calculator was not to hand. It uses the keyword EVAL to evaluate the result of an expression contained in B$. B$ is the accumulated input.

The conversion from fraction to percentage routine expects the percentage value to be entered to two places of decimals, i.e. it expects the player to key in 66.66 not 66.7. If the programmer requires more or fewer decimal places, then A$ in line 510 should be changed accordingly. The trick to write a number to a certain number of decimal places is to multiply it by 10 to the power of the number of decimal places you require, then find the integral part, then divide by the same number. In the program the fraction F/G is multiplied by a further 100 before conversion as the number is a percentage.

Even though the answer is given to a certain number of decimal places any answer, provided it is within 1 of the correct answer, is accepted. This is so that the answer is marked correct however inaccurate the method used to obtain it. The most accurate method is to use the calculator routine provided but players may prefer to use mental arithmetic for speed.

Different types of problems can be added as described in Profit and Loss.



   10 REM QUIZ         - FRACTIONS AND P
ERCENTAGES
   20 REM COPYRIGHT (C) G.LUDINSKI 1983
   30 MODE 4
   40 DIM IP$(255)
   50 S$="                              
          "
   60 HC$=" Highest score ":HK$="     Sc
ore "
   70 COLOUR1:COLOUR 128:PRINT:PRINT:PRI
NT:PRINT"Quiz game 3 - Fractions and per
centages"
   80 PRINT:PRINT
   90 INPUT"Hello, what is your name ",N
AM$:PRINT:PRINT"Here are some problems "
;:IF NAM$ <> "NO SOUND" THEN PRINTNAM$ E
LSE PRINT
  100 W=1:C=0:T=1:I$="":TIME=0:P=0:MAX=0
  102 P=P+1
  104 PROC_QUESTION
  110 PRINT:PRINTQ$" = ";:PROC_KEYIN:PRI
NT
  120 IFI$="?"THEN PROC_CALC
  130 IF W=-1 ANDI$=A$ AND I$<>"" THEN G
OTO 160
  140 IF W=1 AND ABS(VAL(I$)-VAL(A$))< 1
 AND I$<>"" THENGOTO160
  150 GOTO180
  160 PRINT:PRINT"Yes, congratulations":
C=C+1:PRINT:IF NAM$="NO SOUND" THEN GOTO
 210
  170 SOUND1,-10,12,10:SOUND1,-10,20,10:
SOUND1,-10,28,10:SOUND1,-10,32,20:SOUND1
,-10,14,20:GOTO 210
  180 IF T=1 THEN PRINTTAB(0,14)"No, "H$
", try again":T=2:GOTO110
  190 PRINT:PRINT"Sorry, the answer is =
":PRINT:PRINT L$:PRINT:PRINT M$
  200 PRINT:PRINT N$
  210 IF TIME >= 30000 THEN PROC_SCORE
  220 PRINT:PRINT"Do you want more (Y/N)
":PROC_KEYIN:PRINT
  230 IF I$<>"Y" AND I$<>"N" AND I$<>"" 
AND I$<>"YES" AND I$<>"NO" THEN GOTO 220
  240 IF I$="Y" OR I$="YES" OR I$="" THE
N T=1:CLS:GOTO102
  242 PROC_SCORE
  244 GOTO 9999
  248 DEFPROC_QUESTION
  250 L$="":M$="":N$="":B=40
  260 W=-W:F=RND(9)
  270 G=RND(9):J1=RND(19)
  280 IF F=G OR F/G=INT(F/G) OR G/F=INT(
G/F) THEN GOTO 260
  290 IF F<G THEN E=INT(F/G*100):J=J1*5
  300 IF G<F THEN E=INT(G/F*100):H=G:G=F
:F=H:J=J1*2
  310 E$=STR$(E):F$=STR$(F):G$=STR$(G):J
$=STR$(J)
  320 IF W=1 THEN GOTO 410
  330 Q$=J$+"% converted into a fraction
"
  340 H$="P % is P/100. If top and botto
m of   fraction are exactly divisible by
 the   same numbers, then divide by thes
e      numbers"
  350 HU=100:FOR I=1 TO 8
  360 IF J/5=INT(J/5) AND HU/5=INT(HU/5)
 THEN J=J/5:HU=HU/5
  370 IF J/2=INT(J/2) AND HU/2=INT(HU/2)
 THEN J=J/2:HU=HU/2
  380 NEXTI:A$=STR$(J)+"/"+STR$(HU)
  390 L$=A$
  400 M$="as "+J$+"/100 = "+A$
  410 IF W=-1 THEN GOTO 460
  420 Q$=F$+"/"+G$+" expressed as a perc
entage"
  430 H$="P/Q is (P/Q) x 100 %"
  440 A$=STR$(INT(F*10000/G)/100):L$=A$+
"%"
  450 M$="as ("+F$+"/"+G$+") x 100 = "+A
$
  460 ENDPROC
  470 DEFPROC_CALC
  480 VP=VPOS:PRINTTAB(0,22)"          C
alculator Mode            "TAB(0,22)
  490 B$=""
  500 I$=GET$:PRINTI$;:B$=B$+I$:IFI$ <> 
"=" AND I$<>"?"ANDB$<>"AC"THENGOTO500
  510 IF B$="?"ORI$="?"THENGOTO550
  520 IFB$="AC"THENPRINTTAB(0,23);S$;TAB
(0,22):B$="":GOTO490
  530 IFLEN(B$)<=1THENGOTO490
  540 PRINTEVAL LEFT$(B$,LEN(B$)-1);TAB(
0,22):GOTO490
  550 PRINTTAB(0,22);S$;S$;TAB(0,VP-1):P
ROC_KEYIN
  552 ENDPROC
  560 DEFPROC_KEYIN
  570 IX=1:VP=VPOS:HP=POS
  572 IP$(IX)=INKEY$(10):IF IP$(IX)="" T
HEN COLOUR0:COLOUR129:PRINTTAB(0,1);INT(
TIME/100);"     ";HC$;MAX;HK$;C:COLOUR 1
:COLOUR128:GOTO572
  580 PRINTTAB(IX+HP,VP);IP$(IX);:IX=IX+
1:IP$(IX)=GET$:IF IP$(IX)<>CHR$(13) THEN
 GOTO580
  590 I$="":FORI=1 TO IX-1:I$=I$+IP$(I):
NEXTI
  600 ENDPROC
  610 DEFPROC_SCORE
  620 CLS
  622 PRINT:PRINT
  630 PRINT:PRINT"Number of problems com
pleted = ";P
  640 PRINT:PRINT"Number correct = ";C
  650 TM=INT(TIME/100):PRINT:PRINT"Time 
taken in seconds = ";TM
  660 IF C<>0 THEN PRINT:PRINT"Time per 
problem in seconds = ";INT(TM/C)
  670 IF C>MAX THEN MAX=C
  680 TIME=0:P=0:C=0
  690 ENDPROC
  700 REM
 9999 REM