- #1
wahaj
- 156
- 2
Homework Statement
I am writing a program in c++ where it inputs card values from the user and stores it in a char type variable. valid inputs are numbers 1-9, t,k,q,j for ten, kind, queen, jack respectively and a for ace. after inputting all the values the program goes like this
Code:
if (!(card1 == 'a'))
{
switch (card1)
{
case '1':
score = score + 1;
break;
case '2':
score = score + 2;
break;
case '3':
score = score + 3;
break;
case '4':
score = score +4;
break;
case '5':
score = score + 5;
break;
case '6':
score = score + 6;
break;
case '7':
score = score + 7;
break;
case '8':
score = score + 8;
break;
case '9':
score = score + 9;
break;
case 't':
case 'j':
case 'k':
case 'q':
score = score + 10;
break;
default:
break;
}
Code:
if (card1 == 'a' || card2 == 'a' || card3 == 'a' || card 4 == 'a' || card5 = 'a')
{
if (21-score <= 11)
{
score = score + 11;
}
else
{
score = score +1;
}
}
On a side note I have never played blackjack before so I am just going by the brief description of the game given in the question. Also this is my first time using switch statement so I don't know I did used it right.