Commit 3d138f93 authored by Michael's avatar Michael

just commit

parent 06fd5e69
......@@ -23,7 +23,7 @@ clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out && echo "$@ is executing..."
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
......
......@@ -4,7 +4,7 @@
#include <ctime>
#include <unistd.h>
void check(const int number1, const int number2, int answer, bool &answerStatus);
void printMessage(bool answerStatus);
void printPassMessage(const int messageType);
void printNotPassMessage(const int messageType);
......@@ -14,13 +14,17 @@ main()
if (::isatty(STDIN_FILENO)) {
std::srand(std::time(0));
}
if (::isatty(STDIN_FILENO)) {
std::cout << "How much is ";
}
int number1 = 0;
int number2 = 0;
bool answerStatus = true;
while (true) {
const int number1 = 1 + std::rand() % 10;
const int number2 = 1 + std::rand() % 10;
if (::isatty(STDIN_FILENO)) {
std::cout << "How much is ";
}
if (answerStatus) {
number1 = 1 + std::rand() % 10;
number2 = 1 + std::rand() % 10;
}
if (::isatty(STDIN_FILENO)) {
std::cout << number1 << " * " << number2 << "?: ";
}
......@@ -29,24 +33,15 @@ main()
if (-1 == answer) {
break;
}
bool answerStatus;
check(number1, number2, answer, answerStatus);
if (false == answerStatus) {
do {
std::cin >> answer;
check(number1, number2, answer, answerStatus);
} while (false == answerStatus);
}
printMessage(answerStatus);
}
return 0;
}
void
check(const int number1, const int number2, int answer, bool &answerStatus)
printMessage(bool answerStatus)
{
const int messageType = 1 + std::rand() % 4;
answerStatus = (answer == number1 * number2);
if (answerStatus) {
printPassMessage(messageType);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment