Commit d9ea2a25 authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'branch6.36' into 'master'

michael.davityan:exercise_06_36 See merge request bpcarm/trainings2017!921
parents bab29fbb 53e13f0b
Pipeline #25458964 failed with stage
in 2 minutes 18 seconds
progname=exercise_06_36
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
all: test1
debug/$(progname): debug/$(progname).o
$(CC) $(CFLAGS) $< -o $@
debug/%.o: debug/%.s
$(CC) -c $(CFLAGS) $< -o $@
debug/%.s: debug/%.ii
$(CC) -S $(CFLAGS) $< -o $@
debug/%.ii: %.cpp | debug
$(CC) -E $(CFLAGS) $< -o $@
debug:
mkdir -p debug
clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
.SECONDARY: debug/%.ii debug/%.s
Excellent!
Keep up the good work!
Excellent!
No. Keep trying.: Don't give up!: No. Keep trying.: Keep up the good work!
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <unistd.h>
void printMessage(const bool answerStatus);
void printPassMessage(const int messageType);
void printNotPassMessage(const int messageType);
int
main()
{
if (::isatty(STDIN_FILENO)) {
std::srand(std::time(0));
}
int number1 = 0;
int number2 = 0;
bool answerStatus = true;
while (true) {
if (::isatty(STDIN_FILENO)) {
std::cout << "How much is ";
}
if (answerStatus) {
number1 = 1 + std::rand() % 10;
number2 = 1 + std::rand() % 10;
}
if (::isatty(STDIN_FILENO)) {
std::cout << number1 << " * " << number2 << "?: ";
}
int answer;
std::cin >> answer;
answerStatus = (number1 * number2 == answer);
if (-1 == answer) {
break;
}
printMessage(answerStatus);
}
return 0;
}
void
printMessage(const bool answerStatus)
{
const int messageType = 1 + std::rand() % 4;
if (answerStatus) {
printPassMessage(messageType);
} else {
printNotPassMessage(messageType);
}
}
void
printPassMessage(const int messageType)
{
assert((messageType >= 1) && (messageType <= 4));
switch (messageType) {
case 1: std::cout << "Very good!\n" ; break;
case 2: std::cout << "Excellent!\n" ; break;
case 3: std::cout << "Nice work!\n" ; break;
case 4: std::cout << "Keep up the good work!\n"; break;
}
}
void printNotPassMessage(const int messageType)
{
assert((messageType >= 1) && (messageType <= 4));
switch (messageType) {
case 1: std::cout << "No. please try again.: "; break;
case 2: std::cout << "Wrong. Try once more.: "; break;
case 3: std::cout << "Don't give up!: " ; break;
case 4: std::cout << "No. Keep trying.: " ; break;
}
}
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