From 403f1472ea998a078c6785fed802f89d617d55d2 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 3 Jul 2016 17:21:02 -0400 Subject: [PATCH 1/5] Code that tells how many of each letter is put --- abcalculator.c | 387 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 abcalculator.c diff --git a/abcalculator.c b/abcalculator.c new file mode 100644 index 0000000..effe542 --- /dev/null +++ b/abcalculator.c @@ -0,0 +1,387 @@ +#include +/* Jack Rosen. The purpose is to find out how many of each character were put*/ +int main() +{ + int amount, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, m = 0, n = 0, o = 0, p = 0, q = 0, r = 0, s = 0, t = 0, u = 0, v = 0, w = 0, x = 0, y = 0, z = 0, A = 0, B = 0, C = 0, D = 0, E = 0, F = 0, G = 0, H = 0, I = 0, J = 0, K = 0, L = 0, M = 0, N = 0, O = 0, P = 0, Q = 0, R = 0, S = 0, T = 0, U = 0, V = 0, W = 0, X = 0, Y = 0, Z = 0; + printf("How many characters do you want in the array?\n"); + scanf("%d", &amount); + char array[amount]; + printf("What do you want to put into the array?\n"); + for (int i = 0; i < amount; i++) + { + scanf("%c",&array[i]); + if (array[i] == '\n' || array[i] == ' ') + { + array[i] = getchar(); + } + switch (array[i]) + { + case 'a': + a++; + break; + case 'b': + b++; + break; + case 'c': + c++; + break; + case 'd': + d++; + break; + case 'e': + e++; + break; + case 'f': + f++; + break; + case 'g': + g++; + break; + case 'h': + h++; + break; + case 'i': + i++; + break; + case 'j': + j++; + break; + case 'k': + k++; + break; + case 'l': + l++; + break; + case 'm': + m++; + break; + case 'n': + n++; + break; + case 'o': + o++; + break; + case 'p': + p++; + break; + case 'q': + q++; + break; + case 'r': + r++; + break; + case 's': + s++; + break; + case 't': + t++; + break; + case 'u': + u++; + break; + case 'v': + v++; + break; + case 'w': + w++; + break; + case 'x': + x++; + break; + case 'y': + y++; + break; + case 'z': + z++; + break; + case 'A': + A++; + break; + case 'B': + B++; + break; + case 'C': + C++; + break; + case 'D': + D++; + break; + case 'E': + E++; + break; + case 'F': + F++; + break; + case 'G': + G++; + break; + case 'H': + H++; + break; + case 'I': + I++; + break; + case 'J': + J++; + break; + case 'K': + K++; + break; + case 'L': + L++; + break; + case 'M': + M++; + break; + case 'N': + N++; + break; + case 'O': + O++; + break; + case 'P': + P++; + break; + case 'Q': + Q++; + break; + case 'R': + R++; + break; + case 'S': + S++; + break; + case 'T': + T++; + break; + case 'U': + U++; + break; + case 'V': + V++; + break; + case 'W': + W++; + break; + case 'X': + X++; + break; + case 'Y': + Y++; + break; + case 'Z': + Z++; + break; + } + } + if (A != 0) + { + printf("A = %d\n", A); + } + if (a != 0) + { + printf("a = %d\n", a); + } + if (B != 0) + { + printf("B = %d\n", B); + } + if (b != 0) + { + printf("b = %d\n", b); + + } + if (C != 0) + { + printf("C = %d\n", C); + } + if (c != 0) + { + printf("c = %d\n", c); + } + if (D != 0) + { + printf("D = %d\n", D); + } + if (d != 0) + { + printf("d = %d\n", d); + } + if (E != 0) + { + printf("E = %d\n", E); + } + if (e != 0) + { + printf("e = %d\n", e); + } + if (F != 0) + { + printf("F = %d\n", F); + } + if (f != 0) + { + printf("f = %d\n", f); + } + if (G != 0) + { + printf("G = %d\n", G); + } + if (g != 0) + { + printf("g = %d\n", g); + } + if (H != 0) + { + printf("H = %d\n", H); + } + if (h != 0) + { + printf("h = %d\n", h); + } + if (I != 0) + { + printf("I = %d\n", I); + } + if (i != 0) + { + printf("i = %d\n", i); + } + if (J != 0) + { + printf("J = %d\n", J); + } + if (j != 0) + { + printf("j = %d\n", j); + } + if (K != 0) + { + printf("K = %d\n", K); + } + if (k != 0) + { + printf("k = %d\n", k); + } + if (L != 0) + { + printf("L = %d\n", L); + } + if (l != 0) + { + printf("l = %d\n", l); + } + if (M != 0) + { + printf("M = %d\n", M); + } + if (m != 0) + { + printf("m = %d\n", m); + } + if (N != 0) + { + printf("N = %d\n", N); + } + if (n != 0) + { + printf("n = %d\n", n); + } + if (O != 0) + { + printf("O = %d\n", O); + } + if (o != 0) + { + printf("o = %d\n", o); + } + if (P != 0) + { + printf("P = %d\n", P); + } + if (p != 0) + { + printf("p = %d\n", p); + } + if (Q != 0) + { + printf("Q = %d\n", Q); + } + if (q != 0) + { + printf("q = %d\n", q); + } + if (R != 0) + { + printf("R = %d\n", R); + } + if (r != 0) + { + printf("r = %d\n", r); + } + if (S != 0) + { + printf("S = %d\n", S); + } + if (s != 0) + { + printf("s = %d\n", s); + } + if (T != 0) + { + printf("T = %d\n", T); + } + if (t != 0) + { + printf("t = %d\n", t); + } + if (U != 0) + { + printf("U = %d\n", U); + } + if (u != 0) + { + printf("u = %d\n", u); + } + if (V != 0) + { + printf("V = %d\n", V); + } + if (v != 0) + { + printf("v = %d\n", v); + } + if (W != 0) + { + printf("W = %d\n", W); + } + if (w != 0) + { + printf("w = %d\n", w); + } + if (X != 0) + { + printf("X = %d\n", X); + } + if (x != 0) + { + printf("x = %d\n", x); + } + if (Y != 0) + { + printf("Y = %d\n", Y); + } + if (y != 0) + { + printf("y = %d\n", y); + } + if (Z != 0) + { + printf("Z = %d\n", Z); + } + if (z != 0) + { + printf("z = %d\n", z); + } + return 0; +} From 89f7a133a3b8dc16034ffa344fb21915bb1d5d8d Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 3 Jul 2016 17:21:45 -0400 Subject: [PATCH 2/5] Code that adds the numbers except the one of the array --- arrayaddition.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 arrayaddition.c diff --git a/arrayaddition.c b/arrayaddition.c new file mode 100644 index 0000000..deb95a0 --- /dev/null +++ b/arrayaddition.c @@ -0,0 +1,29 @@ +#include +/*Jack Rosen. The purpose is to add all of the numbers except the number in the array and put it in its place.*/ +int main() +{ + int amount, sum; + printf("How many numbers do you want in your array\n"); + scanf("%d", &amount); + int input[amount], output[amount]; + printf("Print the numbers below\n"); + for (int inputAmount = 0; inputAmount < amount; inputAmount ++) + { + scanf("%d", &input[inputAmount]); + } + for (int i = 0; i < amount; i++) + { + sum = 0; + for (int j = 0; j < amount; j++) + { + if (j == i) + { + continue; + } + sum += input[j]; + } + output[i] = sum; + printf("%d\n", output[i]); + } + return 0; +} From 4db6e47a58a616148d3b97db42929a28e0d47826 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 3 Jul 2016 17:22:24 -0400 Subject: [PATCH 3/5] Completed text file --- assignment4.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 assignment4.txt diff --git a/assignment4.txt b/assignment4.txt new file mode 100644 index 0000000..4b48146 --- /dev/null +++ b/assignment4.txt @@ -0,0 +1,5 @@ +Jack Rosen +1.The biggest difference between a string and a character array is a string has the '\0' character at the end. +2. Arrays are very helpful when using the same data type. They are not helpful if they are from a different data type. Also, there is no checking mechanism for array sizes. +3. This occurs when an array name appears in an expression such as when its an operand of the sizeof operator, or as an operand of & operator. +4. Each character would be compared and if they were all equal, a 0 would be the output. From d9c4f455dbee88f1f0f6d87b42e0ec4b329c4ca0 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 3 Jul 2016 17:22:56 -0400 Subject: [PATCH 4/5] Completed file that removes duplicate from array --- comparison.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 comparison.c diff --git a/comparison.c b/comparison.c new file mode 100644 index 0000000..c740bbc --- /dev/null +++ b/comparison.c @@ -0,0 +1,46 @@ +#include +/*Jack Rosen. The purpose is to remove the duplicates of the array and reput the array*/ +int main() +{ + int amount, i = 0, j = 0; + printf("How long would you like the array to be?\n"); + scanf("%d", &amount); + char array1[amount]; + printf("What would you want in the array? \n"); + for(i = 0; i < amount; i++) + { + array1[i] = ' '; + } + i = 0; + while (i < amount) + { + + scanf("%c", &array1[i]); + if (array1[i] == '\n') + { + array1[i] = getchar(); + } + for (j = 0; j < i; j++) + { + if (i == j) + { + break; + } + else if (array1[i] == array1[j]) + { + i--; + amount--; + } + } + i += 1; + } + i = 0; + while (i < amount) + { + printf("%c", array1[i]); + i++; + } + printf("\n"); + + return 0; +} From 50d4b4137a00cd5addfa3182e650ef2c74784287 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 3 Jul 2016 17:23:35 -0400 Subject: [PATCH 5/5] Completed code that plays a game of hangman --- hangman.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 hangman.c diff --git a/hangman.c b/hangman.c new file mode 100644 index 0000000..b4929bf --- /dev/null +++ b/hangman.c @@ -0,0 +1,72 @@ +#include +/*Jack Rosen. The purpose is to play a game of hangman*/ +int main() +{ + char guess[6] = "crazy", input, answer[8] = "_____ ", incorrectarray[9] = " "; + int sum = 0, incorrectint = 0; + float incorrect = 0; + printf("You get 8 incorrect guesses.\n"); + printf("The word has 5 letters \n _____\n"); + while (sum < 5 && incorrect < 8) + { + printf("What do you think is one letter?\n"); + scanf("%c", &input); + if (input == '\n') + { + input = getchar(); + } + for (int i = 0; i < 8; i++) + { + if (input == guess[i]) + { + sum++; + answer[i] = input; + } + else + { + + incorrect += .125; + } + } + for (int i = 0; i < 6; i++) + { + printf("%c", answer[i]); + } + printf("\n"); + incorrectint = (int)incorrect / 1; + if (sum == 5) + { + printf("You win, the word was crazy\n"); + break; + } + if (incorrect == 8) + { + printf("You have had too many incorrect guesses so you lose\n"); + break; + } + printf("Your incorrect letters are: \n"); + for(int j = 0; j < 9; j++) + { + + if (incorrectarray[j] != ' ' && incorrectarray[j] != '\0') + { + printf("%c", incorrectarray[j]); + } + if (incorrect == incorrectint) + { + if ( incorrectarray[j] == ' ') + { + incorrectarray[j] = input; + printf("%c", incorrectarray[j]); + break; + + } + } + } + incorrect = incorrectint; + printf("\n"); + printf("You have made %d incorrect guesses\n", incorrectint); + + } + return 0; +}