From 19b7d28b128c2456244318e4d471f0d6bcf81049 Mon Sep 17 00:00:00 2001 From: Deathsbreed Date: Thu, 30 Oct 2014 11:19:33 -0500 Subject: [PATCH] Added source. --- .gitignore | 2 ++ Makefile | 25 +++++++++++++++++++++++++ src/main.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c00a739 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Ignore binaries +bin/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0cf095e --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +CXX=gcc +CXXFLAGS= -O3 -Wall -std=gnu99 + +INCLUDES= +LIBS= + +MV=mv +MKDIR=mkdir -p +RM=rm -rf + +SRC_FILES := $(wildcard src/*.c) +OBJ_FILES := $(addprefix src/, $(notdir $(SRC_FILES:.c=.o))) + +all: $(OBJ_FILES) + $(MKDIR) bin + $(CXX) $(CXXFLAGS) $(LIBS) -o bin/cointoss src/*.o + +src/%.o: src/%.c + $(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $< + +clean: + $(RM) src/*.o + +fullclean: clean + $(RM) bin diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..c74f5e6 --- /dev/null +++ b/src/main.c @@ -0,0 +1,30 @@ +#include +#include +#include + +char version[7] = "v0.1"; + +int main(int argc, char **argv) { + printf("Welcome to Coin Toss %s\n", version); + if(argc < 2 || argc > 3) { + printf("Usage: %s [trials]\n", argv[0]); + return 1; + } + + int trials = atoi(argv[1]); + int heads = 0; + int tails = 0; + + srand(time(NULL)); + + for(int i = 0; i < trials; i++) { + int r = rand() % 100 + 1; + if(r <= 50) heads++; + else tails++; + } + + printf("Done.\n"); + printf("Heads: %i\n", heads); + printf("Tails: %i\n", tails); + return 0; +}