Commit 95ec3c2c authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'exe_36' into 'master'

exercise_06_36, version1

See merge request bpcarm/trainings2017!1344
parents ddd330f3 c5f44b00
progname = exercise_06_36
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
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;
while (true) {
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;
}
}
return 0;
}
Excellent!
Keep up the good work!
Excellent!
No.Keep trying.
Don't give up.
No.Keep trying.
Keep up the good work!
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