Changed problem structure

This commit is contained in:
Pin
2022-04-03 19:08:44 -04:00
parent aa0528664c
commit 19f05508db

29
msh.c
View File

@@ -13,10 +13,12 @@
#include "msh.h" #include "msh.h"
#define clear() printf("\033[H\033[J") #define clear() printf("\033[H\033[J")
#define MATHLEN 100000
static char *prompt = NULL; static char *prompt = NULL;
static bool skipMath = false; static bool skipMath = false;
static size_t mathLen = 100;
static size_t commandRun = 0;
static char *mathOperation = "+-";
union pipe { union pipe {
int fileDesc[2]; int fileDesc[2];
@@ -271,7 +273,7 @@ char *getPrompt() {
int randomNum(int limit) { int randomNum(int limit) {
int num = 0; int num = 0;
if (limit != 0) { if (limit != 0) {
num = rand()%limit +1; num = rand()%limit + 1;
} else { } else {
num = rand(); num = rand();
} }
@@ -281,14 +283,12 @@ int randomNum(int limit) {
int mathTest() { int mathTest() {
int status = 0; int status = 0;
long numAnswer = 0; long numAnswer = 0;
int num1 = randomNum(MATHLEN); int num1 = randomNum(mathLen);
int num2 = randomNum(MATHLEN); int num2 = randomNum(mathLen);
long numSolution = 0; long numSolution = 0;
char *numLine = NULL; char *numLine = NULL;
const char mathOperation[] = {'+', '-', '*', '/'}; int randProblem = randomNum(strlen(mathOperation)) - 1;
int randProblem = randomNum(3);
if (skipMath) { if (skipMath) {
return 0; return 0;
@@ -308,6 +308,9 @@ int mathTest() {
case '/': case '/':
numSolution = num1 / num2; numSolution = num1 / num2;
break; break;
default:
numSolution = 0;
break;
} }
#ifndef RELEASEBUILD #ifndef RELEASEBUILD
@@ -336,6 +339,17 @@ int mathTest() {
return status; return status;
} }
void postCommand() {
commandRun++;
if ((commandRun % 3) == 0) {
mathLen *= 10;
}
if (commandRun == 3) {
mathOperation = "+-*/";
}
return;
}
void startShell() { void startShell() {
char *line = NULL; char *line = NULL;
@@ -347,6 +361,7 @@ void startShell() {
if (status == 0) { // Passed math test if (status == 0) { // Passed math test
add_history(line); add_history(line);
execCommand(line); execCommand(line);
postCommand();
} else { // Failed math test } else { // Failed math test
failedTest(); failedTest();
} }