diff --git a/bin/agg b/bin/agg new file mode 100755 index 0000000..623c2c8 Binary files /dev/null and b/bin/agg differ diff --git a/obj/agg.o b/obj/agg.o new file mode 100644 index 0000000..de67509 Binary files /dev/null and b/obj/agg.o differ diff --git a/src/agg.c b/src/agg.c index c095d7e..c81ccd0 100644 --- a/src/agg.c +++ b/src/agg.c @@ -3,6 +3,7 @@ #include #include #include +#include int main(void) { srand(time(NULL)); printf ("Hello World!\nThis is a game written for AgnoxGD.\nWould you like to see a tutorial\nType 1 for no, or 0 for yes.\n"); @@ -28,10 +29,6 @@ int main(void) { int end_time = unix_time + playtime; int score = 0; -// int qa; -// int tl; -// int st; -// I can't remember what the fuck these are for while (unix_time < end_time) { float num1 = rand() % number_length + 1; @@ -39,6 +36,7 @@ int main(void) { int type = rand() % 4 + 1; float result; float answer; + char entered[20]; // DEBUG //printf("%g, %g and %d\n", num1, num2, type); @@ -46,25 +44,59 @@ int main(void) { if (type == 1) { printf ("Add %g and %g\n", num1, num2); result = num1 + num2; - scanf ("%g", &answer); unix_time = time(NULL); } else if (type == 2) { printf ("Divide %g by %g\n", num1, num2); result = num1 / num2; - scanf ("%g", &answer); unix_time = time(NULL); } else if (type == 3) { printf ("Subtract %g from %g\n", num2, num1); result = num1 - num2; - scanf ("%g", &answer); unix_time = time(NULL); } else if (type == 4) { printf ("Multiply %g by %g\n", num1, num2); result = num1 * num2; - scanf ("%g", &answer); unix_time = time(NULL); } + scanf ("%s", entered); + int valid = 1; + for (int i = 0; i < strlen(entered); i++) { + switch (entered [i]) { + case '0': + break; + case '1': + break; + case '2': + break; + case '3': + break; + case '4': + break; + case '5': + break; + case '6': + break; + case '7': + break; + case '8': + break; + case '9': + break; + case '.': + break; + default: + valid = 0; + } + } + + if (valid == 1) { + sscanf (entered, "%g", &answer); + } else { + printf ("Error! An invalid character was entered.\n"); + exit (1); + } + if (result == answer) { printf ("Correct!\n"); score++;