From 3334346f81944597725433b3bae1a535ed494b16 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 5 Feb 2024 16:03:44 +0100 Subject: [PATCH] Implementierung getRandCard, liefert Zufallszahl zwischen 1 und 10 --- src/main/c/Stefan/blackjack.c | 22 ++++++++++++++++++++++ src/main/c/Stefan/blackjack.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index 9c353d4..5a0a77d 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -1,5 +1,7 @@ #include "blackjack.h" #include +#include +#include int blackjack(){ @@ -10,6 +12,7 @@ int blackjack(){ int balance = getBalanceBJ(); int bet = getBetBJ(balance); printf("bet: %d\n", bet); + printf("rand card: %d\n", getRandCard()); return 0; } @@ -42,3 +45,22 @@ int userInputBJ(){ scanf("%d", &input); return input; } + +// Liefert eine Zufallszahl zwischen 1 und 10 +// Chance für 10 ist 4 Mal höher als für den Rest +// 1 = Ass +int getRandCard(){ + + srand(time(NULL)); + + int r = rand() % 13; + r++; + + if(r > 10){ + return 10; + } + + return r; + + +} \ No newline at end of file diff --git a/src/main/c/Stefan/blackjack.h b/src/main/c/Stefan/blackjack.h index 8f7fe1e..bfc4f73 100644 --- a/src/main/c/Stefan/blackjack.h +++ b/src/main/c/Stefan/blackjack.h @@ -6,5 +6,6 @@ int blackjack(); int getBalanceBJ(); int getBetBJ(int balance); int userInputBJ(); +int getRandCard(); #endif // BLACKJACK_H \ No newline at end of file