Commit b32e295a authored by Michael's avatar Michael

michael.davityan:exercise_06_35new

parent c5ef7019
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <climits>
#include <unistd.h> #include <unistd.h>
void printMessage(bool answerStatus); void printMessage(bool answerStatus);
...@@ -15,23 +14,25 @@ main() ...@@ -15,23 +14,25 @@ main()
std::srand(std::time(0)); std::srand(std::time(0));
} }
bool answerStatus = true; bool answerStatus = true;
int number1 = 0;
int number2 = 0;
while (true) { while (true) {
if (::isatty(STDIN_FILENO)) { if (::isatty(STDIN_FILENO)) {
std::cout << "How much is "; std::cout << "How much is ";
} }
if (answerStatus) { if (answerStatus) {
int number1 = 1 + std::rand() % 10; number1 = 1 + std::rand() % 10;
int number2 = 1 + std::rand() % 10; number2 = 1 + std::rand() % 10;
} }
if (::isatty(STDIN_FILENO)) { if (::isatty(STDIN_FILENO)) {
std::cout << Number1 << " * " << Number2 << "?: "; std::cout << number1 << " * " << number2 << "?: ";
} }
int answer; int answer;
std::cin >> answer; std::cin >> answer;
if (-1 == answer) { if (-1 == answer) {
break; break;
} }
answerStatus = (answer == Number1 * Number2); answerStatus = (answer == number1 * number2);
printMessage(answerStatus); printMessage(answerStatus);
} }
return 0; return 0;
......
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