Commit a101d8da authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'exe_37' into 'master'

exercise_06_37, version1

See merge request bpcarm/trainings2017!1345
parents 95ec3c2c efde9628
progname = exercise_06_37
CC = g++
CFLAGS = -Wall -Wextra -Werror -g3
$(progname): $(progname).o | .gitignore
$(CC) $(CFLAGS) $^ -o $@
%.ii: %.cpp
$(CC) -E $(CFLAGS) $< -o $@
%.s: %.ii
$(CC) -S $(CFLAGS) $< -o $@
%.o: %.s
$(CC) -c $(CFLAGS) $< -o $@
.gitignore:
echo $(progname) > $@
clean:
rm -f *.ii *.s *.o *.out $(progname) .gitignore
test%: $(progname)
./$(progname) < $@.in > $@.out 2>&1 || echo "$@ is executing..."
diff $@.out $@.expected && echo PASSED || echo FAILED
.PRECIOUS: $(progname).ii $(progname).s
.SECONDARY: $(progname).ii $(progname).s
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <ctime>
std::string
printCorrectAnswer()
{
const int answerType = 1 + std::rand() % 4;
std::string response;
switch(answerType) {
case 1: response = "Very good!"; break;
case 2: response = "Excellent!"; break;
case 3: response = "Nice work!"; break;
case 4: response = "Keep up the good work!"; break;
default: response = "Good job"; break;
}
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
main()
{
if (::isatty(STDIN_FILENO)) {
std::srand(std::time(0));
}
int first = 0;
int second = 0;
bool answerStatus = true;
int count = 10;
int incorrectAnswerCount = 10;
while (count != 0) {
if (answerStatus) {
first = 1 + std::rand() % 10;
second = 1 + std::rand() % 10;
}
if (::isatty(STDIN_FILENO)) {
std::cout << "How much " << first << " times " << second << "? ";
}
int answer;
std::cin >> answer;
if (-1 == answer) {
break;
}
answerStatus = (first * second == answer);
if (answerStatus) {
std::cout << printCorrectAnswer() << std::endl;
} else {
std::cout << printIncorrectAnswer() << std::endl;
--incorrectAnswerCount;
--count;
}
}
const int result = incorrectAnswerCount * 10;
if (result < 75) {
std::cout << "Please ask your instructor for extra help." << std::endl;
return 0;
}
std::cout << "Good job!!!" << std::endl;
return 0;
}
Excellent!
No.Keep trying.
Nice work!
Wrong.Try once more.
Don't give up.
No.Keep trying.
Don't give up.
No.Keep trying.
No.Keep trying.
Don't give up.
Please try again.
Don't give up.
Please ask your instructor for extra help.
Wrong.Try once more.
No.Keep trying.
Wrong.Try once more.
No.Keep trying.
Don't give up.
Please try again.
Wrong.Try once more.
Wrong.Try once more.
Nice work!
No.Keep trying.
No.Keep trying.
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