diff options
| -rw-r--r-- | README.md | 6 | ||||
| -rwxr-xr-x | build.sh | 7 | ||||
| -rw-r--r-- | stats.c | 36 |
3 files changed, 24 insertions, 25 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..2aa95bb --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Stats counter +compile with `make` + +usage: stats <numbers> + +you must include multiple numbers or there is no use diff --git a/build.sh b/build.sh deleted file mode 100755 index e980568..0000000 --- a/build.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -clear - -vim stats.c - -make @@ -14,9 +14,9 @@ void help(){ } /* ADDING UP ALL THE VALUES */ -int sigma(int argc, char * argv[]) { +long sigma(int argc, char * argv[]) { char *endptr; - int sum = 0; + long sum = 0; for (int i = 1; i < argc; i++) { @@ -36,12 +36,12 @@ float average(int n, int sum) { } /* FINDING THE MIN/MAX/DIFFERENCE */ -int range(int argc, char * argv[], enum MODE mode) { - int low = strtol(argv[1], NULL, 10); - int high = low; +long range(int argc, char * argv[], enum MODE mode) { + long low = strtol(argv[1], NULL, 10); + long high = low; for (int i = 1; i < argc; i++) { - int val = strtol(argv[i], NULL, 10); + long val = strtol(argv[i], NULL, 10); if (val > high) high = val; if (low > val) low = val; } @@ -63,19 +63,19 @@ int main(int argc, char * argv[]) { help(); } - int n = argc - 1; /* this is how many numbers there are */ - int sum = sigma(argc, argv); /* sigma means adding them all together */ - float mean = average(n, sum); /* the sum divided by the however many numbers there are */ - int min = range(argc, argv, MODE_MIN); /* Using enums here to use words instead of numbers */ - int max = range(argc, argv, MODE_MAX); - int diff = range(argc, argv, MODE_DIFF); + long n = argc - 1; /* this is how many numbers there are */ + long sum = sigma(argc, argv); /* sigma means adding them all together */ + float mean = average(n, sum); /* the sum divided by the however many numbers there are */ + long min = range(argc, argv, MODE_MIN); /* Using enums here to use words instead of numbers */ + long max = range(argc, argv, MODE_MAX); + long diff = range(argc, argv, MODE_DIFF); /* align text left for 6 and 12 right */ - printf("%-6s %12d\n", "num:", n); - printf("%-6s %12d\n", "sum:", sum); - printf("%-6s %12.3f\n", "mean:", mean); - printf("%-6s %12d\n", "min:", min); - printf("%-6s %12d\n", "max:", max); - printf("%-6s %12d\n", "range:", diff); + printf("%-6s %12ld\n", "num:", n); + printf("%-6s %12ld\n", "sum:", sum); + printf("%-6s %12.3f\n", "mean:", mean); + printf("%-6s %12ld\n", "min:", min); + printf("%-6s %12ld\n", "max:", max); + printf("%-6s %12ld\n", "range:", diff); } |