scoring a blackjack hand

i'm making a program that scores a blackjack hand but i don't know how to make ten, jack, queen, and king to have a value of 10 when the user has one of these in their hand.
this is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
using namespace std;
int main()
{
    char a, total_cards;
    int total, c2, c3, c4, c5, c6, c7, c8, c9;
    const int t=10, j=10, q=10, k=10;
    bool cards;

    
    do
    {
    cout<<"How many cards do you have in your hand?\n";
    cin>>total_cards;
    switch (total_cards)
    {
          case '2':
               cout<<"You have 2 cards, what are they?\n";
               cout<<"what is the first card?\n";
               cin>>c2;
               cout<<"what is the second card?\n";
               cin>>c3;
               if (c2=a)
               c2==1;
               total=c2+c3;
               cout<<endl<<"The value of your hand is: "<<total;
               break;
          case '3':
               cout<<"You have 3 cards, what are they?\n";
               cout<<"what is the first card?\n";
               cin>>c2;
               cout<<"what is the second card?\n";
               cin>>c3;
               cout<<"what is the third card?\n";
               cin>>c4;
               total=c2+c3+c4;
               cout<<endl<<"The value of your hand is: "<<total;
               break;
          case '4':
               cout<<"You have 4 cards, what are they?\n";
               cout<<"what is the first card?\n";
               cin>>c2;
               cout<<"what is the second card?\n";
               cin>>c3;
               cout<<"what is the third card?\n";
               cin>>c4;
               cout<<"what is the forth card?\n";
               cin>>c5;
               total=c2+c3+c4+c5;
               cout<<endl<<"The value of your hand is: "<<total;
               break;
          case '5':
               cout<<"You have 5 cards, what are they?\n";
               cout<<"what is the first card?\n";
               cin>>c2;
               cout<<"what is the second card?\n";
               cin>>c3;
               cout<<"what is the third card?\n";
               cin>>c4;
               cout<<"what is the forth card?\n";
               cin>>c5;
               cout<<"what is the fifth card?\n";
               cin>>c5;
               total=c2+c3+c4+c5+c6;
               cout<<endl<<"The value of your hand is: "<<total;
               break;
          default:
                  cout<<"You must have between 2-5 cards in your hand\n";
    }
    }while (cards);
    
    
    cin>>c3;
    
    return 0;
}
you could do an if statement.

if (c1 == 'Q' || c1 == 'q' || c1 == 'j' || c1 == 'J' || c1 == 'K' || c1 == 'k' ) c1 = 10;

just a note : characters are actually integer numbers so you can compare an int to a char no problem
Last edited on
you may also want to do something like
 
if(total > 21 && (c1 == 'a' || c2 == 'a')) { a = 1; } else a = 11;


this will adjust your ace to 1 or 11 depending on the total value.. so if you hit with an A + 9 and decide to hit, and say oyu get a 2 you will then have 12 not 22
so i added
1
2
3
4
5
6
7
8
9
10
11
12
case '2':
               cout<<"You have 2 cards, what are they?\n";
               cout<<"what is the first card?\n";
               cin>>c2;
               if (c2 == 'Q' || c2 == 'q' || c2 == 'j' || c2 == 'J' || c2 == 'K' || c2 == 'k' ) 
               c2 = 10;
               cout<<"what is the second card?\n";
               cin>>c3;
               if (total>22)
               cout<<"BUSTED!!\n";
               cout<<endl<<"The value of your hand is: "<<total;
               break;

and i got

How many cards do you have in your hand (you can have 2-5 cards)?
2
You have 2 cards, what are they?
what is the first card?
t
what is the second card?
BUSTED!!

The value of your hand is: 2293576Press any key to continue . . .
give me a minute i'll crack the problem
any luck?
Topic archived. No new replies allowed.