Commit efde9628 authored by Karine's avatar Karine

exercise_06_37, finally

parent 404c7c3c
...@@ -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()
...@@ -63,18 +68,21 @@ main() ...@@ -63,18 +68,21 @@ main()
} }
answerStatus = (first * second == answer); answerStatus = (first * second == answer);
if (!answerStatus) {
if (answerStatus) {
std::cout << printCorrectAnswer() << std::endl;
} else {
std::cout << printIncorrectAnswer() << std::endl;
--incorrectAnswerCount; --incorrectAnswerCount;
--count;
} }
std::cout << printAnswer(answerStatus) << std::endl;
--count;
} }
const int result = incorrectAnswerCount * 10; const int result = incorrectAnswerCount * 10;
if (result < 75) { if (result < 75) {
std::cout << "Please ask your instructor for extra help." << std::endl; std::cout << "Please ask your instructor for extra help." << std::endl;
return 1; return 0;
} }
std::cout << "Good job!!!" << std::endl; std::cout << "Good job!!!" << std::endl;
......
...@@ -8,4 +8,6 @@ Don't give up. ...@@ -8,4 +8,6 @@ Don't give up.
No.Keep trying. No.Keep trying.
No.Keep trying. No.Keep trying.
Don't give up. Don't give up.
Please try again.
Don't give up.
Please ask your instructor for extra help. Please ask your instructor for extra help.
...@@ -8,4 +8,3 @@ ...@@ -8,4 +8,3 @@
28 28
7 7
21 21
...@@ -8,4 +8,5 @@ Wrong.Try once more. ...@@ -8,4 +8,5 @@ Wrong.Try once more.
Wrong.Try once more. Wrong.Try once more.
Nice work! Nice work!
No.Keep trying. No.Keep trying.
No.Keep trying.
Please ask your instructor for extra help. Please ask your instructor for extra help.
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