Browse Source

Implementierung getRandCard, liefert Zufallszahl zwischen 1 und 10

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
3334346f81
  1. 22
      src/main/c/Stefan/blackjack.c
  2. 1
      src/main/c/Stefan/blackjack.h

22
src/main/c/Stefan/blackjack.c

@ -1,5 +1,7 @@
#include "blackjack.h" #include "blackjack.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <time.h>
int blackjack(){ int blackjack(){
@ -10,6 +12,7 @@ int blackjack(){
int balance = getBalanceBJ(); int balance = getBalanceBJ();
int bet = getBetBJ(balance); int bet = getBetBJ(balance);
printf("bet: %d\n", bet); printf("bet: %d\n", bet);
printf("rand card: %d\n", getRandCard());
return 0; return 0;
} }
@ -42,3 +45,22 @@ int userInputBJ(){
scanf("%d", &input); scanf("%d", &input);
return 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;
}

1
src/main/c/Stefan/blackjack.h

@ -6,5 +6,6 @@ int blackjack();
int getBalanceBJ(); int getBalanceBJ();
int getBetBJ(int balance); int getBetBJ(int balance);
int userInputBJ(); int userInputBJ();
int getRandCard();
#endif // BLACKJACK_H #endif // BLACKJACK_H
Loading…
Cancel
Save