From 9f69d94d3c16e36f547dda58a3f890bebec894b2 Mon Sep 17 00:00:00 2001 From: Christian Reum Date: Tue, 6 Feb 2024 18:56:24 +0100 Subject: [PATCH] functional 17: checkAnswer (useranswer == 5) --- src/wwm.c | 20 ++++++++++++++++++-- src/wwm.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/wwm.c b/src/wwm.c index e15b08e..849d60d 100644 --- a/src/wwm.c +++ b/src/wwm.c @@ -8,6 +8,8 @@ int geld = 0; int frage = 0; int useranswer; +int ceingabe(); + int setGeld(int runde){ int Geldstufen[] = {0, 100, 200, 300, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 125000, 250000, 500000, 1000000}; geld = Geldstufen[runde]; @@ -22,10 +24,24 @@ int crandomNumber() { } + +void ccheckAnswer(int useranswer) { + if (useranswer == 5) { + printf("That is a shame, but ok.\n"); + printf("Congratulations! You have won %d $!", geld); + exit(0); + } +} + int ceingabe() { printf("Your answer (1-4):"); - scanf("%d", &useranswer); - return useranswer; + int result = scanf_s("%d", &useranswer); + if (result == 0) { + printf("Please enter a number beetween 1 and 4 to answer or 5 to end the game!\n"); + while (getchar() != '\n') + return ceingabe(); + return useranswer; + } }; void wwm(){ diff --git a/src/wwm.h b/src/wwm.h index ab4ba12..3a461f8 100644 --- a/src/wwm.h +++ b/src/wwm.h @@ -10,6 +10,7 @@ extern int Geldstufen[]; int crandomNumber(); int ceingabe(); +void ccheckAnswer(); int setGeld(int runde);