So im basically trying to do a loop with some if statements in it, and the problem with the loop is that the user is going to enter a choice, either H or S. However, when the user enter S, the program goes straight to the H statement and goes through that and after it, it goes to the other statement. Let me show you with the code:
int decision(struct CardDeck *deck) {
char choice;
printf("Value is %d\n", deck->ValueOfSecondPlayer);
while (deck->ValueOfSecondPlayer <= 21)
{
if (deck->ValueOfSecondPlayer == 21) {
printf("Blackjack!");
}
if (deck->ValueOfSecondPlayer > 21) {
printf("Sorry, you lose");
}
if (deck->ValueOfSecondPlayer < 21) {
printf("Would you like to hit or stand?\n");
scanf("%c", &choice);
}
if (choice == 'H' || choice == 'h'); {
printf("You wish to hit, heres your card\n");
deck->ValueOfSecondPlayer += printCards(deck);
printf("Your total is now %d\n", deck->ValueOfSecondPlayer);
}
if (choice == 'S' || choice == 's') {
printf("You wished to stay\n");
break;
}
}
}
So the output im getting when i enter S is:
Value is 18
Would you like to hit or stand?
S
You wish to hit, heres your card
Jack of Clubs
Your total is now 28
You wished to stay
Pess any key to continue . . .
And when i enter H the program runs like this:
Value is 16
Would you like to hit or stand?
h
You wish to hit, heres your card
4 of Clubs
Your total is now 20
Would you like to hit or stand?
You wish to hit, heres your card
2 of Spades
Your total is now 22
Press any key to continue . . .
So my problem here is that the program goes into the choice H and h even though i use S or s. I dont know if im dumb or something, but if anyone can tell me what im doing wrong and how to fix the problem i would be greatful!
Thanks!
Aucun commentaire:
Enregistrer un commentaire