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"
#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();
}