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