blackjack program face cards problem

hello
alright, i made a blackjack program, it works. i don't know what i would do for the face cards, like jack,king,queen,and ace, how would i put them into a random generator. the jack,king,queen count as 10. also how would i get the ace to count as either 11 or 1, when needed.

i know the indentation is off, but its better than other programs that i have made.
also any hints if i could put more into a loop or something.

Regarding card values, have a look at enums, it would probably be better for you to store the cards as enums....setting the values yourself. You can then set the face value cards to all equal ten. Maybe set the value of an ace at 1 initially and then if the need arises, you can always add another 10 to the final hand score?

I am actually writing my own blackjack program right now! I handled the issue by having a "caseOfAce" variable, which increases by one every time an ace is drawn. I used the following code to generate cards.

After every drawn card, a checkBust() function is called, which checks if the hand's new total value is over 21. If the value is over 21 and caseOfAce is greater than 0, subtract one from caseOfAce and subtract 10 from the total value, then rerun the check.

ok
i got the program to output face cards, and gave them values for when i put them in.
my program crashes if i put in letters(face cards) when it asks what cards i have, it also doesnt continue in the beginning if it outputs a facecard. i still dont get how i would change the ace from 1 to 11 if needed. i was thinking

There are a number of issues with this code. Before I get to them, I'd like to suggest to you this: if ever, when programming, you find yourself manually typing out sections of repeated code, ask yourself if it can't be done automatically by the computer itself. You could probably cut this code down 80% by using loops or reorganizing; and that will be a major help with bug-fixing and generally enhancing code-readability!

To be honest, I simply cannot understand why you took the approach to this problem you did. Why do you have variables n1,...,n5 if their values are only used once? You could replace them all with a single variable "n". Moreover, the variables 'j,q,k,a' are completely unused and do nothing in your program after assignment. Keep in mind that the use of a variable comes from its ability to vary. Every unneeded extra variable means increased code complexity and increased memory usage.

Why do you ask the player for input on how many cards they have, or what values the cards were? Doing that is completely redundant, since the computer has already generated a card for you, and can easily keep track of how many it has generated. This is where you could reduce your code significantly--a single "while" loop would be able to handle all of the card-generation, counting, and bust-checking.

The overall loop is also awkward. Why does it count down from 10? This limits the number of times a player can play--sometimes this is useful, but here I don't think that's the point. Any infinite loop would be appropriate here, because as you have a "break" command when the user types that they don't want to repeat, there is a way to escape the loop.

I think that if you rewrite the card-generation etc within a loop, the rest of your problems will disappear--and if not, they will be a LOT easier to solve. Give it a shot, and be sure to post your solution!