reprompt math question on C^d

This commit is contained in:
Pin
2022-12-15 13:37:44 -05:00
parent 43dce73c81
commit d19edeabcd

16
msh.c
View File

@@ -316,10 +316,15 @@ int mathTest() {
#ifndef RELEASEBUILD #ifndef RELEASEBUILD
printf("Answer: %ld\n", numSolution); printf("Answer: %ld\n", numSolution);
#endif #endif
printf("%d %c %d = ", num1, mathOperation[randProblem], num2); while(numLine == NULL) {
numLine = readline(""); printf("%d %c %d = ", num1, mathOperation[randProblem], num2);
if (numLine != NULL && strlen(numLine) > 0) { numLine = readline("");
sscanf(numLine, "%ld", &numAnswer);
if (numLine != NULL && strlen(numLine) > 0) {
sscanf(numLine, "%ld", &numAnswer);
}
free(numLine);
} }
if (numSolution != numAnswer) { // If wrong answer if (numSolution != numAnswer) { // If wrong answer
@@ -337,7 +342,6 @@ int mathTest() {
printf("\n"); printf("\n");
#endif #endif
free(numLine);
return status; return status;
} }
@@ -370,6 +374,8 @@ void startShell() {
} }
free(line); free(line);
} }
printf("Exiting Shell\n");
sleep(2);
free(prompt); free(prompt);
prompt = NULL; prompt = NULL;
} }