diff options
Diffstat (limited to '10_gdb/game.c')
-rw-r--r-- | 10_gdb/game.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/10_gdb/game.c b/10_gdb/game.c new file mode 100644 index 0000000..a7459d3 --- /dev/null +++ b/10_gdb/game.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/time.h> +int getSecretNumber(void); //prototype, implemented elsewhere. + +int getOtherSN(int which); //prototype, implemented elsewhere. + +int main(void) { + int guessesMade = 0; + int yourGuess; + char buffer[1024]; + int myNumber = getSecretNumber(); + + printf("I'm thinking of a number...\n"); + printf("What number do you guess?\n"); + if(fgets(buffer, 1024, stdin) == NULL) { + printf("Oh no, you are giving up? You lose...\n"); + return EXIT_FAILURE; + } + yourGuess = atoi(buffer); + if(yourGuess != myNumber) { + printf("I'm sorry, that is not right. You lose\n"); + return EXIT_FAILURE; + } + printf("Correct! You win round1!\n"); + + int total = 0; + for (int i = 0; i <= 5678; i++) { + total = total ^ getOtherSN(i); + } + printf("Ok, time for round 2. I have another secret number.\n"); + printf("Your guess:\n"); + if(fgets(buffer, 1024, stdin) == NULL) { + printf("Oh no, you are giving up? You lose...\n"); + return EXIT_FAILURE; + } + yourGuess = atoi(buffer); + if (yourGuess == total) { + printf("You win round 2 also!\n"); + return EXIT_SUCCESS; + } + printf("Sorry, you did not win the second round\n"); + return EXIT_FAILURE; +} |