Commit 42b6b15c authored by Karine's avatar Karine

exercise_06_35, version2

parent 9f29a898
......@@ -21,7 +21,7 @@ clean:
rm -f *.ii *.s *.o *.out $(progname) .gitignore
test: $(progname)
./$(progname)
./$(progname) < $@.in > $@.out
diff $@.out $@.expected && echo PASSED || echo FAILED
.PRECIOUS: $(progname).ii $(progname).s
......
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
void
printAnswer(bool answerStatus)
{
if (answerStatus) {
std::cout << "Very good!\n";
} else {
std::cout << "No. Please try again.: ";
}
}
int
main()
{
for(int i = 0; i < 10; ++i) {
int first = std::rand() % 10;
int second = std::rand() % 10;
std::cout << "How much is " << first << " times " << second << " ? ";
if (::isatty(STDIN_FILENO)) {
std::srand(std::time(0));
}
bool answerStatus = true;
int first = 0;
int second = 0;
while (true) {
if (answerStatus) {
first = 1 + std::rand() % 10;
second = 1 + std::rand() % 10;
}
if (::isatty(STDIN_FILENO)) {
std::cout << "How much is " << first << " times " << second << " ? ";
}
int answer;
std::cin >> answer;
if(answer == first * second) {
std::cout << "Very good!" << std::endl;
}
else {
///bool test =true;
do {
std::cout << "Try again!" << std::endl;
std::cout << "How much is " << first << " times " << second << " ? ";
std::cin >> answer;
if(answer == first * second) {
std::cout << "Good!" << std::endl;
}
} while(answer != first * second);
if (-1 == answer) {
break;
}
answerStatus = (answer == first * second);
printAnswer(answerStatus);
}
return 0;
......
Very good!
Very good!
Very good!
No. Please try again.: No. Please try again.: No. Please try again.: Very good!
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