Commit ddd330f3 authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'exe_06_34_' into 'master'

exercise_06_34, version1

See merge request bpcarm/trainings2017!1367
parents 5535571b b69466ef
progname = exercise_06_34
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) > $@.out
diff $@.out $@.expected && echo PASSED || echo FAILED
.PRECIOUS: $(progname).ii $(progname).s
.SECONDARY: $(progname).ii $(progname).s
#include <iostream>
#include <cstdlib>
#include <ctime>
bool
flip()
{
return static_cast<bool>(std::rand() % 2);
}
int
main()
{
int tailsCounter = 0;
int eagleCounter = 0;
std::srand(std::time(0));
for (int counter = 1; counter <= 100; ++counter) {
if (flip()) {
++tailsCounter;
} else {
++eagleCounter;
}
}
std::cout << "flipped tails " << tailsCounter << " times" << std::endl
<< "flipped eagle " << eagleCounter << " times" << std::endl;
return 0;
}
flipped tails 49 times
flipped eagle 51 times
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