Added source.

This commit is contained in:
Deathsbreed 2014-10-30 11:19:33 -05:00
parent 10d897d6d2
commit 19b7d28b12
3 changed files with 57 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Ignore binaries
bin/

25
Makefile Normal file
View File

@ -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

30
src/main.c Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
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;
}