From 95ed3720adbb25fa441c4244981ba346fa4946ce Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 28 Oct 2024 21:46:27 +0200 Subject: [PATCH] Using AI to improve code readability --- Math/Multiplication trainer.bas | 112 ++++++++++++++++---------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/Math/Multiplication trainer.bas b/Math/Multiplication trainer.bas index 473f63e..a10f090 100644 --- a/Math/Multiplication trainer.bas +++ b/Math/Multiplication trainer.bas @@ -2,22 +2,22 @@ ' By Svjatoslav Agejenko. ' Email: svjatoslav@svjatoslav.eu ' Homepage: http://www.svjatoslav.eu -' + ' Changelog: ' 2000, Initial version ' 2024, Improved program readability using AI -DECLARE SUB vastus () +DECLARE SUB showGreetingAndSetup () DEFINT A-Y -DECLARE SUB tere () -DIM SHARED nimi$ -DIM SHARED kus +DECLARE SUB getUserInputAndDisplayQuestions () +DIM SHARED userName$ +DIM SHARED numberOfQuestions -tere -vastus +showGreetingAndSetup +getUserInputAndDisplayQuestions DEFINT Z -SUB tere +SUB showGreetingAndSetup ' Clear the screen and set up graphics mode CLS @@ -29,26 +29,26 @@ PRINT " Math teaching program" FOR y = 3 TO 20 FOR x = 0 TO 320 IF POINT(x, y) > 0 THEN - c = y + 56 + colorIndex = y + 56 ELSE - c = 31 - y / 2 + colorIndex = 31 - y / 2 END IF - PSET (x, y), c + PSET (x, y), colorIndex NEXT x NEXT y ' Get user input for their name LOCATE 5, 1 COLOR 7 -INPUT "Enter your name ", nimi$ +INPUT "Enter your name ", userName$ LOCATE 5, 1 COLOR 8 -PRINT "Enter your name " + nimi$ +PRINT "Enter your name " + userName$ ' Greet the user LOCATE 6, 1 COLOR 7 -PRINT "Hello " + nimi$ + "!" +PRINT "Hello " + userName$ + "!" 8 LOCATE 7, 1 @@ -56,21 +56,21 @@ COLOR 8 PRINT SPACE$(35) COLOR 7 LOCATE 7, 1 -INPUT "How many questions would you like ? ", kus +INPUT "How many questions would you like ? ", numberOfQuestions LOCATE 7, 1 COLOR 8 PRINT SPACE$(35) LOCATE 7, 1 COLOR 8 -PRINT "How many questions would you like ?" + STR$(kus) +PRINT "How many questions would you like? " + STR$(numberOfQuestions) ' Validate the number of questions -IF kus < 5 THEN +IF numberOfQuestions < 5 THEN PRINT "That would be too easy !" GOTO 8 END IF -IF kus > 30 THEN +IF numberOfQuestions > 30 THEN PRINT "That would be too hard !" GOTO 8 END IF @@ -87,23 +87,23 @@ FOR a = 200 TO 230 NEXT ' Initialize color array -DIM varv(1 TO 32) +DIM colorArray(1 TO 32) -c = 4 -d = 1 +currentColorIndex = 4 +colorChangeDirection = 1 2 FOR a = 0 TO 31 ' Draw vertical lines with decreasing brightness - LINE (a * 10, 170)-(a * 10 + 10, 190), 200 + varv(a + 1), BF - varv(a + 1) = varv(a + 1) - 1 - IF varv(a + 1) < 0 THEN varv(a + 1) = 0 + LINE (a * 10, 170)-(a * 10 + 10, 190), 200 + colorArray(a + 1), BF + colorArray(a + 1) = colorArray(a + 1) - 1 + IF colorArray(a + 1) < 0 THEN colorArray(a + 1) = 0 NEXT a ' Change the color index -c = c + d -IF c > 30 OR c < 3 THEN d = -d -varv(c) = 30 +currentColorIndex = currentColorIndex + colorChangeDirection +IF currentColorIndex > 30 OR currentColorIndex < 3 THEN colorChangeDirection = -colorChangeDirection +colorArray(currentColorIndex) = 30 SOUND 0, 1 ' Check if user is ready @@ -115,52 +115,52 @@ CLS END SUB DEFSNG Z -SUB vastus +SUB getUserInputAndDisplayQuestions RANDOMIZE TIMER -mitmes = 0 -vale = 0 -oige = 0 +numberOfAttempts = 0 +incorrectAnswers = 0 +correctAnswers = 0 PRINT "How much is:" 4 -mitmes = mitmes + 1 -IF mitmes > kus THEN GOTO 6 +numberOfAttempts = numberOfAttempts + 1 +IF numberOfAttempts > numberOfQuestions THEN GOTO 6 ' Generate random numbers for multiplication -ar1 = RND * 9 -ar2 = RND * 9 -a$ = STR$(ar1) + " X" + STR$(ar2) +multiplier1 = RND * 9 +multiplier2 = RND * 9 +question$ = STR$(multiplier1) + " X" + STR$(multiplier2) PRINT " " -PRINT a$ +PRINT question$ 5 -INPUT vas$ +INPUT userAnswer$ ' Handle invalid inputs -IF LEFT$(vas$, 6) = "don't know" THEN +IF LEFT$(userAnswer$, 6) = "don't know" THEN PRINT "Try at least !" GOTO 5 END IF ' Convert input to number -IF vas$ = "0" THEN - vas = 0 +IF userAnswer$ = "0" THEN + userAnswer = 0 GOTO 10 ELSE - vas = VAL(vas$) - IF vas = 0 THEN vas = -1 + userAnswer = VAL(userAnswer$) + IF userAnswer = 0 THEN userAnswer = -1 END IF 10 ' Check if the answer is correct -IF ar1 * ar2 = vas THEN - oige = oige + 1 +IF multiplier1 * multiplier2 = userAnswer THEN + correctAnswers = correctAnswers + 1 PRINT "Correct !" ELSE PRINT "Wrong !" - PRINT "Correct answer is ", ar1 * ar2 - vale = vale + 1 + PRINT "Correct answer is ", multiplier1 * multiplier2 + incorrectAnswers = incorrectAnswers + 1 END IF GOTO 4 @@ -168,19 +168,19 @@ GOTO 4 6 PRINT "-------------------------" COLOR 2 -PRINT "Wrong answers :", vale +PRINT "Incorrect answers: ", incorrectAnswers ' Calculate the score -z = oige / kus * 100 +scorePercentage = correctAnswers / numberOfQuestions * 100 -hinne = 1 +grade = 1 ' Determine the grade -IF z >= 25 THEN hinne = 2 -IF z >= 50 THEN hinne = 3 -IF z >= 70 THEN hinne = 4 -IF z >= 90 THEN hinne = 5 +IF scorePercentage >= 25 THEN grade = 2 +IF scorePercentage >= 50 THEN grade = 3 +IF scorePercentage >= 70 THEN grade = 4 +IF scorePercentage >= 90 THEN grade = 5 COLOR 14 -PRINT "Your grade is: "; hinne -END SUB \ No newline at end of file +PRINT "Your grade is: "; grade +END SUB -- 2.20.1