Commit bab29fbb authored by Believer Programmers' Club's avatar Believer Programmers' Club

Merge branch 'branch6.35' into 'master'

michael.davityan:exercise_06_35 See merge request bpcarm/trainings2017!911
parents bf8a4a24 b32e295a
Pipeline #25420386 failed with stage
in 51 seconds
progname=exercise_06_35
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
Very good!
Very good!
Very good!
No. Please try again.: No. Please try again.: No. Please try again.: Very good!
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
void printMessage(bool answerStatus);
void printPassMessage();
void printNotPassMessage();
int
main()
{
if (::isatty(STDIN_FILENO)) {
std::srand(std::time(0));
}
bool answerStatus = true;
int number1 = 0;
int number2 = 0;
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;
if (-1 == answer) {
break;
}
answerStatus = (answer == number1 * number2);
printMessage(answerStatus);
}
return 0;
}
void
printMessage(bool answerStatus)
{
if (answerStatus) {
printPassMessage();
} else {
printNotPassMessage();
}
}
void
printPassMessage()
{
std::cout << "Very good!\n";
}
void
printNotPassMessage()
{
std::cout << "No. Please try again.: ";
}
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