Commit 9779220e by karlki

blackjack.c

parent 09f0e942
Showing with 90 additions and 0 deletions
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
srand(time(NULL));
char *kaardid[13] = {"2","3","4","5","6", "7","8","9","10","J","Q", "K", "A"};
char *cV6etud[13];
char *pV6etud[13];
int pCount = 0;
int cCount = 0;
int player = 0;
int computer = 0;
int i = 0;
int lost = 0;
for (; i< 2; i++) {
cV6etud[i] = kaardid[(rand() % 13)];
pV6etud[i] = kaardid[(rand() % 13)];
pCount++;
cCount++;
}
for (i = 0; i < 2; i++) {
if (cV6etud[i] == "J" || cV6etud[i] == "Q" || cV6etud[i] == "K"||cV6etud[i] == "A" ) {
if (cV6etud[i] == "A") {
if (computer == 11) {
computer = computer + 1;
} else {
computer = computer + 11;
}
} else {
computer = computer + 10;
}
} else {
computer = computer + atoi(cV6etud[i]);
}
if (pV6etud[i] == "J" || pV6etud[i] == "Q" || pV6etud[i] == "K" || pV6etud[i] == "A") {
if (pV6etud[i] == "A") {
if (player == 11) {
player = player + 1;
} else {
player = player + 11;
}
} else {
player = player + 10;
}
} else {
player = player + atoi(pV6etud[i]);
}
}
printf("Arvuti: %d [ ", computer);
for (i = 0; i < cCount; i++) {
printf("%s ", cV6etud[i]);
}
printf ("] \n");
printf("Sina: %d [ ", player);
for (i = 0; i < pCount; i++) {
printf("%s ", pV6etud[i]);
}
printf ("] \n");
if (player == 21) {
printf("Palju 6nne v6itsid arvutit!\n");
lost = 1;
}
if (computer == 21) {
printf("Arvuti v6itis, sa kaotasid!\n");
lost = 1;
}
while (lost == 0) {
printf("siin peaks programm t66tama!\n");
lost = 1;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment