13 Commits
v0.1 ... v0.2

Author SHA1 Message Date
537bc64413 Update README.md 2014-11-04 15:57:26 -06:00
bea82bc7f5 Fixed progress problem by using long long int 2014-11-04 15:56:07 -06:00
4d89477bce Trying to use progress. 2014-11-04 11:59:32 -06:00
5c1c5654d1 Simplified an if statement. 2014-11-04 11:44:52 -06:00
fd31a58e26 Changed version string. 2014-11-04 11:42:51 -06:00
072029db8a Using obj/ for .o files. 2014-11-04 11:41:35 -06:00
53d372675d Simplifying if statements. 2014-11-04 11:32:55 -06:00
231437872a Misplaced double-quote. 2014-11-03 19:49:14 -06:00
0e63f6af23 Added to a comment. 2014-11-03 11:50:05 -06:00
165213a1ad Added comments. 2014-11-03 11:47:49 -06:00
f116a4727c Fixed failsafe. 2014-11-03 10:07:27 -06:00
23e0889167 Will create deb outside project. 2014-10-30 18:14:00 -05:00
ed5f340e68 Ignore deb creating directory. 2014-10-30 18:10:59 -05:00
4 changed files with 55 additions and 20 deletions

View File

@ -9,17 +9,17 @@ MKDIR=mkdir -p
RM=rm -rf
SRC_FILES := $(wildcard src/*.c)
OBJ_FILES := $(addprefix src/, $(notdir $(SRC_FILES:.c=.o)))
OBJ_FILES := $(addprefix obj/, $(notdir $(SRC_FILES:.c=.o)))
all: $(OBJ_FILES)
$(MKDIR) bin
$(CXX) $(CXXFLAGS) $(LIBS) -o bin/cointoss src/*.o
$(CXX) $(CXXFLAGS) $(LIBS) -o bin/cointoss obj/*.o
src/%.o: src/%.c
obj/%.o: src/%.c
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $<
clean:
$(RM) src/*.o
$(RM) obj/*.o
cleanall: clean
$(RM) bin

View File

@ -1,7 +1,7 @@
CoinToss
========
The creation of this program has a little story. I was in math class and a classmate was playing around with the probability simulator on his TI Calculator. He was trying to do as many coin tosses as he could, until finally he reached 9999, which was the limit of tosses for the simulator. So I decided that I would create this, which allows you to do more than that, specifically 2,147,473,649 more times than that.
The creation of this program has a little story. I was in math class and a classmate was playing around with the probability simulator on his TI Calculator. He was trying to do as many coin tosses as he could, until finally he reached 9999, which was the limit of tosses for the simulator. So I decided that I would create this, which allows you to do more than that, specifically 9,223,372,036,854,765,808 more trials than that.
### Compiling
To compile make sure you have the GNU C Compiler installed (GCC) and just go to the root directory of this project and run:

1
obj/readme.txt Normal file
View File

@ -0,0 +1 @@
This is where the object output files go. This readme file is a simple hack so that git registers it (git doesn't register empty directories).

View File

@ -16,52 +16,85 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
char version[7] = "v0.1";
// Global version string
char version[7] = "v0.2";
/* Function prototypes start */
void printCopyright();
void printAllCopyright();
void printWarranty();
/* Function prototypes end */
// Main function:
int main(int argc, char **argv) {
if(argc < 2 || argc > 3) {
printf("Usage: %s [trials]\n", argv[0]);
// If inappropriate number of arguments
if(argc < 2 || argc > 3) { // If inappropriate number of arguments (number required = 2)
printf("Inappropriate amount of arguments.\n");
printf("Usage: %s [num_trials]\n", argv[0]);
return 1;
}
if(strcmp(argv[1], "-c") == 0) {
if(!strcmp(argv[1], "-c")) { // If argv[1] (the second argument) is equal to "-c" ...
printAllCopyright();
return 0;
} else if(strcmp(argv[1], "-w") == 0) {
} else if(!strcmp(argv[1], "-w")) { // If argv[1] is equal to "-w"
printWarranty();
return 0;
} else if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { // If argv[1] is equal to "-h" or "--help"
printf("Usage: %s [num_trials]\n\
-c -- Print copyright info\n\
-h | --help -- Print this help information\n\
-w -- Print warranty information\n", argv[0]);
return 0;
} else {
int i = 0;
while(argv[1][i] != '\0') { // While argv[1][i] is not equal to NULL (can't use NULL for pointers)
if(isdigit(argv[1][i] - '0')) { // if argv[1][i] is not a number between 0 and 9
printf("You did not specify a number.\n");
printf("Usage: %s [num_trials]\n", argv[0]);
return 1;
}
i++;
}
}
printCopyright();
int trials = atoi(argv[1]);
int heads = 0;
int tails = 0;
long long int trials = atoi(argv[1]);
long long int heads = 0;
long long int tails = 0;
// Setup the random number generator with the seed being the time
srand(time(NULL));
printf("Working...\n");
for(int i = 0; i < trials; i++) {
if(i % 100000000 == 0) printf("Working...\n");
int r = rand() % 100 + 1;
long long int oldprogress = 0;
printf("Calculating random numbers...\n");
printf("Progress: 0 %%\n");
for(long long int i = 0; i < trials; i++) {
long long int progress = (i * 100) / trials;
if(progress != oldprogress && progress % 10 == 0) {
printf("Progress: %lli %%\n", progress);
oldprogress = progress;
}
int r = rand() % 100 + 1; // Calculate random number between 1 and 100
if(r <= 50) heads++;
else tails++;
}
printf("Progress: 100 %%\n");
printf("Done.\n");
printf("Heads: %i\n", heads);
printf("Tails: %i\n", tails);
printf("Done.\n\n");
printf("Heads: %lli\n", heads);
printf("Tails: %lli\n", tails);
return 0;
}
/* Defined functions start */
void printCopyright() {
printf("CoinToss %s Copyright (C) 2014 Nicolás A. Ortega\n\
This program comes with ABSOLUTELY NO WARRANTY; for details use `-w'.\n\
@ -94,3 +127,4 @@ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\n\
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\n\
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n");
}
/* Defined functions end */