From 19f05508dbed3ae2c2081b5b7c3ba89e89c739b3 Mon Sep 17 00:00:00 2001 From: Pin Date: Sun, 3 Apr 2022 19:08:44 -0400 Subject: [PATCH] Changed problem structure --- msh.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/msh.c b/msh.c index 9348d8a..590a655 100644 --- a/msh.c +++ b/msh.c @@ -13,10 +13,12 @@ #include "msh.h" #define clear() printf("\033[H\033[J") -#define MATHLEN 100000 static char *prompt = NULL; static bool skipMath = false; +static size_t mathLen = 100; +static size_t commandRun = 0; +static char *mathOperation = "+-"; union pipe { int fileDesc[2]; @@ -271,7 +273,7 @@ char *getPrompt() { int randomNum(int limit) { int num = 0; if (limit != 0) { - num = rand()%limit +1; + num = rand()%limit + 1; } else { num = rand(); } @@ -281,14 +283,12 @@ int randomNum(int limit) { int mathTest() { int status = 0; long numAnswer = 0; - int num1 = randomNum(MATHLEN); - int num2 = randomNum(MATHLEN); + int num1 = randomNum(mathLen); + int num2 = randomNum(mathLen); long numSolution = 0; char *numLine = NULL; - const char mathOperation[] = {'+', '-', '*', '/'}; - - int randProblem = randomNum(3); + int randProblem = randomNum(strlen(mathOperation)) - 1; if (skipMath) { return 0; @@ -308,6 +308,9 @@ int mathTest() { case '/': numSolution = num1 / num2; break; + default: + numSolution = 0; + break; } #ifndef RELEASEBUILD @@ -336,6 +339,17 @@ int mathTest() { return status; } +void postCommand() { + commandRun++; + if ((commandRun % 3) == 0) { + mathLen *= 10; + } + + if (commandRun == 3) { + mathOperation = "+-*/"; + } + return; +} void startShell() { char *line = NULL; @@ -347,6 +361,7 @@ void startShell() { if (status == 0) { // Passed math test add_history(line); execCommand(line); + postCommand(); } else { // Failed math test failedTest(); }