Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pascalated ZX BASIC Demo #3 - Multiplication Table
#1
To run online, click here: RUN ONLINE


Code:
' PROGRAM MULTIPLICATION TABLE
' Demo for Pascalated BASIC contest
' Version ZX SPECTRUM (c) 1983 by Zarsoft
' Version ZX BASIC Boriel (c) 2023 by Zarsoft
' Language: Pascalated ZX BASIC (BORIEL) compiled

#include <input.bas>

'--- Pascalated Boriel ---
#define VAR       DIM
#define INTEGER   LONG
#define REAL      FLOAT
#define BOOLEAN   LONG
#define TYPE      AS
#define REPEAT    DO
#define UNTIL     LOOP UNTIL
#define PROCEDURE SUB
#define PROGRAM   REM
VAR     TRUE      TYPE INTEGER = 1
VAR     FALSE     TYPE INTEGER = 0

REM Variable Declarations
VAR GoodScore TYPE BOOLEAN = FALSE : REM many right answers
VAR Name$ TYPE STRING = "" : REM User name
VAR RightAnswers TYPE INTEGER = 0 : REM number of right answers
VAR Question$ TYPE STRING : REM the question
VAR Answer TYPE INTEGER = 0 : REM user answer
VAR Level TYPE INTEGER = 0 : REM difficulty level
VAR Attempt TYPE INTEGER : REM number of questions

PROCEDURE Write (line$ TYPE STRING)
REM POKE 23692,9
FOR n=0 TO LEN(line$)-1
  PRINT line$(n);
  BEEP .02,10+10*RND
NEXT n
END PROCEDURE

PROCEDURE WriteLine  (line$ TYPE STRING)
Write(line$)
PRINT
END PROCEDURE

PROCEDURE CheckAnswer
VAR line$ TYPE STRING
PRINT
IF ABS (VAL Question$-Answer) > .01
  WriteLine( " Wrong, "+Name$+"." )
  WriteLine( " "+Question$+" = "+STR$( VAL( Question$ ) ) )
ELSE
  LET RightAnswers = RightAnswers + 1
  WriteLine( " Right, "+Name$+"." )
  WriteLine( " "+Question$+" = "+STR$( Answer ) )
ENDIF
PAUSE 25
WriteLine( " "+STR$ RightAnswers +" right answers in "+STR$ Attempt+"." )
PAUSE 2*50
END PROCEDURE

PROCEDURE AskQuestion
VAR reply$ TYPE STRING
REPEAT
  Write( " "+Question$+" = " )
  reply$ = INPUT(9) : PRINT reply$
UNTIL VAL reply$ > 0
LET Answer = VAL reply$
END PROCEDURE

PROCEDURE ChooseNumbers
VAR N1 TYPE INTEGER
VAR N2 TYPE INTEGER
RANDOMIZE
N1 = 2*Level+INT (4*Level*RND)
N2 = 2*Level+INT (3*Level*RND)
LET Question$ = STR$ N1 + " * " + STR$ N2
PRINT
END PROCEDURE

PROCEDURE AskOneQuestion
ChooseNumbers
AskQuestion
CheckAnswer
END PROCEDURE

PROCEDURE ChooseDifficulty
WriteLine( "What difficulty do you like? " )
REPEAT
  Write( "1, 2 or 3? " )
  Level = VAL INPUT (9) : PRINT Level
UNTIL Level >= 1 AND Level <= 3
PRINT
END PROCEDURE

PROCEDURE GameOver
PRINT
WriteLine( " Well done!" )
WriteLine( " You don't need me anymore..." )
WriteLine( " Goodbye!" )
END PROCEDURE

PROCEDURE GradeTheTest
PRINT
IF RightAnswers > 8
  LET GoodScore = TRUE
ELSE
  LET GoodScore = FALSE
  PRINT
  WriteLine(" "+STR$ RightAnswers + " right answers in 10?!")
  WriteLine(" This is not good...")
  WriteLine(" Let's try again!")
ENDIF
END PROCEDURE

PROCEDURE AskTenQuestions
PRINT
ChooseDifficulty
LET RightAnswers = 0
PRINT CHR$(13, 13, 13, 13, 13, 13)
FOR Attempt = 1 TO 10
  AskOneQuestion
NEXT Attempt
END PROCEDURE

PROCEDURE InitVariables
LET RightAnswers = 0
LET GoodScore = 0
END PROCEDURE

PROCEDURE Hello
VAR line$ TYPE STRING
CLS
PRINT "Demo for "
PRINT "2023 Pascalated BASIC contest"
PRINT
PRINT "(c) 2023 by Zarsoft"
PRINT
PRINT "Compiled language:"
PRINT "Pascalated ZX BASIC (Boriel)"
PRINT CHR$(13, 13, 13, 13, 13)
WriteLine(" Hi, Human!")
REPEAT
  Write(" What is your name? ")
  Name$ = INPUT (20) : PRINT Name$
UNTIL LEN Name$ >= 2
PRINT
WriteLine(" Hi, "+Name$+"!")
WriteLine(" I am your new teacher.")
PAUSE 50
PRINT
WriteLine(" I'm going to see if you know the multiplication table...")
END PROCEDURE

PROCEDURE MainRoutine
Hello
REPEAT
  InitVariables
  AskTenQuestions
  GradeTheTest
UNTIL GoodScore
GameOver
END PROCEDURE

PROGRAM MainRoutine
MainRoutine
' last 2 lines are going to be deleted
PRINT CHR$(13, 13, 13)
END PROGRAM
Reply
#2
Wow, nice to see it really works!!  Cool  Heart
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)