From cb7e1688c61dc6861d06b56475f46d5c7ac75f91 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Mon, 1 Nov 2021 11:10:32 -0400 Subject: Updated coin to allow for multiple flips --- .DS_Store | Bin 6148 -> 6148 bytes .vscode/configurationCache.log | 2 +- .vscode/dryrun.log | 2 +- .vscode/targets.log | 22 ++++++++---------- ProjectMustang.txt | 14 ------------ README.txt | 14 ++++++++++++ src/cmd/coin/coin.c | 49 ++++++++++++++++++++++++++++++++++++----- src/cmd/dice/dice.c | 2 +- src/cmd/echo/echo.c | 2 +- 9 files changed, 71 insertions(+), 36 deletions(-) delete mode 100644 ProjectMustang.txt create mode 100644 README.txt diff --git a/.DS_Store b/.DS_Store index 1c7c9d9..b48a754 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.vscode/configurationCache.log b/.vscode/configurationCache.log index c60bec6..3fb4b13 100644 --- a/.vscode/configurationCache.log +++ b/.vscode/configurationCache.log @@ -1 +1 @@ -{"buildTargets":["all","clean","cmd/.","coin/.","dice/.","echo/.","install","src"],"launchTargets":["/Users/jmm/Documents/git/ProjectMustang/src/cmd/coin>coin()","/Users/jmm/Documents/git/ProjectMustang/src/cmd/dice>dice()","/Users/jmm/Documents/git/ProjectMustang/src/cmd/echo>echo()"],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":["/Users/jmm/Documents/git/ProjectMustang/src/cmd/coin","/Users/jmm/Documents/git/ProjectMustang/src/cmd/dice","/Users/jmm/Documents/git/ProjectMustang/src/cmd/echo"],"compilerArgs":["-o","echo","echo.c"]},"fileIndex":[["/Users/jmm/Documents/git/ProjectMustang/src/cmd/coin/coin.c",{"uri":{"$mid":1,"fsPath":"/Users/jmm/Documents/git/ProjectMustang/src/cmd/coin/coin.c","path":"/Users/jmm/Documents/git/ProjectMustang/src/cmd/coin/coin.c","scheme":"file"},"configuration":{"defines":[],"standard":"c11","includePath":[],"forcedInclude":[],"intelliSenseMode":"clang-x64","compilerPath":"/usr/bin/cc","compilerArgs":["-o","coin","coin.c"],"windowsSdkVersion":""}}],["/Users/jmm/Documents/git/ProjectMustang/src/cmd/dice/dice.c",{"uri":{"$mid":1,"fsPath":"/Users/jmm/Documents/git/ProjectMustang/src/cmd/dice/dice.c","path":"/Users/jmm/Documents/git/ProjectMustang/src/cmd/dice/dice.c","scheme":"file"},"configuration":{"defines":[],"standard":"c11","includePath":[],"forcedInclude":[],"intelliSenseMode":"clang-x64","compilerPath":"/usr/bin/cc","compilerArgs":["-o","dice","dice.c"],"windowsSdkVersion":""}}],["/Users/jmm/Documents/git/ProjectMustang/src/cmd/echo/echo.c",{"uri":{"$mid":1,"fsPath":"/Users/jmm/Documents/git/ProjectMustang/src/cmd/echo/echo.c","path":"/Users/jmm/Documents/git/ProjectMustang/src/cmd/echo/echo.c","scheme":"file"},"configuration":{"defines":[],"standard":"c11","includePath":[],"forcedInclude":[],"intelliSenseMode":"clang-x64","compilerPath":"/usr/bin/cc","compilerArgs":["-o","echo","echo.c"],"windowsSdkVersion":""}}]]}} \ No newline at end of file +{"buildTargets":["all","clean","install","src"],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}} \ No newline at end of file diff --git a/.vscode/dryrun.log b/.vscode/dryrun.log index 4edcbd5..51f061e 100644 --- a/.vscode/dryrun.log +++ b/.vscode/dryrun.log @@ -1,4 +1,4 @@ -make all -f "/Users/jmm/Documents/git/ProjectMustang/makefile" --dry-run --keep-going --print-directory +make all -f "/Users/jmm/Documents/git/ProjectMustang/makefile" --dry-run --always-make --keep-going --print-directory make: Entering directory `/Users/jmm/Documents/git/ProjectMustang' make: Nothing to be done for `all'. make: Leaving directory `/Users/jmm/Documents/git/ProjectMustang' diff --git a/.vscode/targets.log b/.vscode/targets.log index 1ccc479..0d9e783 100644 --- a/.vscode/targets.log +++ b/.vscode/targets.log @@ -6,13 +6,11 @@ make all -f "/Users/jmm/Documents/git/ProjectMustang/makefile" --print-data-base # PARTICULAR PURPOSE. # This program built for i386-apple-darwin11.3.0 - -# Make data base, printed on Sun Oct 10 19:18:58 2021 +# Make data base, printed on Mon Nov 1 10:33:21 2021 # Variables - # automatic #include #include +#include + +int coinFlip (int times); int -main (void) +main (int argc, char *argv[]) { - int c; - time_t t; - srand((unsigned) time(&t)); + int nflag = 0, i, times = 1, tails, heads; + argc--; - printf("%s\n", (rand() % 2) ? "Heads" : "Tails"); + for (i = 1; i <= argc; i++) { + if (strcmp(argv[i], "-n") == 0) + nflag++; + else if (nflag == 1) + times = atoi(argv[i]); + if (times == 0) { + printf("Non Integer Value Inputted\n"); + return -1; + } + } + if (times == 1) + printf("%s\n", coinFlip(times) ? "Heads" : "Tails"); + else { + tails = coinFlip(times); + heads = times - tails; + float ph = (float)heads/times, pt = (float)tails/times; + + printf("Heads: %d\nTails: %d\nProb Heads: %f\nProb Tails: %f\n", heads, tails, ph, pt); + } return 0; } + +/* coinFlip: Flips a coin n numbers of times and returns the number of tails */ +int +coinFlip (int times) +{ + int tails, i, c; + time_t t; + srand((unsigned) time(&t)); + + tails = 0; + + for (i = 0; i < times; i++) { + c = rand() % 2; + if (c == 1) + tails++; + } + + return tails; +} \ No newline at end of file diff --git a/src/cmd/dice/dice.c b/src/cmd/dice/dice.c index b31670f..f211d67 100644 --- a/src/cmd/dice/dice.c +++ b/src/cmd/dice/dice.c @@ -12,4 +12,4 @@ main (void) printf("%d\n", (rand() % sides) + 1); return 0; -} +} \ No newline at end of file diff --git a/src/cmd/echo/echo.c b/src/cmd/echo/echo.c index 4733830..3dc8334 100644 --- a/src/cmd/echo/echo.c +++ b/src/cmd/echo/echo.c @@ -14,4 +14,4 @@ main (int argc, char *argv[]) printf("%s%c", argv[i], (i == argc) ? ((nflag == 1) ? '\0' : '\n') : ' '); } return 0; -} +} \ No newline at end of file -- cgit v1.2.3