Commit 579b7015 authored by Believer Programmers' Club's avatar Believer Programmers' Club

Merge branch 'exe_35' into 'master'

exercise_06_35, version1

See merge request bpcarm/trainings2017!1343
parents 4a0e6005 42b6b15c
progname = exercise_06_35
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 <ctime>
#include <unistd.h>
void
printAnswer(bool answerStatus)
{
if (answerStatus) {
std::cout << "Very good!\n";
} else {
std::cout << "No. Please try again.: ";
}
}
int
main()
{
if (::isatty(STDIN_FILENO)) {
std::srand(std::time(0));
}
bool answerStatus = true;
int first = 0;
int second = 0;
while (true) {
if (answerStatus) {
first = 1 + std::rand() % 10;
second = 1 + std::rand() % 10;
}
if (::isatty(STDIN_FILENO)) {
std::cout << "How much is " << first << " times " << second << " ? ";
}
int answer;
std::cin >> answer;
if (-1 == answer) {
break;
}
answerStatus = (answer == first * second);
printAnswer(answerStatus);
}
return 0;
}
Very good!
Very good!
Very good!
No. Please try again.: No. Please try again.: No. Please try again.: Very good!
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