ok so i have to make a blackjack game or "21" but the twist is that they get to pick how many cards they have and what the cards are (stupid i know but its what the spec says so i have to do it)
anyway i have it all set out so it works but they have the option to pick J Q K A but i dont know how to change i if they pick that to a number... can someone please help, thank you in advance :) x
thank you for your help, i think im gonna attempt option two beucase i think they want us to accept letters, the only question i have is that will string carry a number that i can add up? because otherwise the date entry that they enter might corrupt the program.
if that didnt make sense i mean if i have
int card
cin >> card
and they put A
can i still do all the if statements? or will it just error?
A string is essentially a character array (with quite a few bells and whistles, but still). Thus, it can carry letters and numbers.
BUT you can't just use a string in a numerical operation (for example you can't add or substract 2 strings, even if they only contain numbers). You need to stringstream the string into an integer (or a float or double, I suppose) if you want to do that.
I just spoke to someone who is doing the same thing but still hasnt finished his, but he is using a switch., can i use a switch to make it add up?
can i use the switch with char?
for example
switch (answer[x])
case 1:
total += 1
case 2
total += 2
case "a":
total +=11
case "k":
total += 10
I suppose it could work, but not quite like you wrote it.
The cases should be in colons even for the numbers ( like so case '1': ), and every case should and with a break command (break;).
The problem is what to do with the 10. Switch can't check two values as far as I know.
BTW, there is no case '1' if you use 'A'; it's either one or the other. And K has a value of 13, not 10.