Commit c5f44b00 authored by Karine's avatar Karine

exercise_06_36, version5

parent 5d777a47
...@@ -4,34 +4,39 @@ ...@@ -4,34 +4,39 @@
#include <unistd.h> #include <unistd.h>
#include <ctime> #include <ctime>
std::string std::string
printAnswer(const bool answerStatus) printCorrectAnswer()
{ {
const int answerType = 1 + std::rand() % 4; const int answerType = 1 + std::rand() % 4;
std::string response; std::string response;
switch(answerType) {
if (answerStatus) { case 1: response = "Very good!"; break;
switch(answerType) { case 2: response = "Excellent!"; break;
case 1: response = "Very good!"; break; case 3: response = "Nice work!"; break;
case 2: response = "Excellent!"; break; case 4: response = "Keep up the good work!"; break;
case 3: response = "Nice work!"; break; default: response = "Good job"; break;
case 4: response = "Keep up the good work!"; break;
default: response = "Good job"; break;
}
} else {
switch(answerType) {
case 1: response = "Please try again."; break;
case 2: response = "Wrong.Try once more."; break;
case 3: response = "Don't give up."; break;
case 4: response = "No.Keep trying."; break;
default: response = "Nooooo"; break;
}
} }
return response; return response;
} }
std::string
printIncorrectAnswer()
{
const int answerType = 1 + std::rand() % 4;
std::string response;
switch(answerType) {
case 1: response = "Please try again."; break;
case 2: response = "Wrong.Try once more."; break;
case 3: response = "Don't give up."; break;
case 4: response = "No.Keep trying."; break;
default: response = "Nooooo"; break;
}
return response;
}
int int
main() main()
...@@ -61,7 +66,12 @@ main() ...@@ -61,7 +66,12 @@ main()
} }
answerStatus = (first * second == answer); answerStatus = (first * second == answer);
std::cout << printAnswer(answerStatus) << std::endl;
if (answerStatus) {
std::cout << printCorrectAnswer() << std::endl;
} else {
std::cout << printIncorrectAnswer() << std::endl;
}
} }
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