Problem from earlier

this is a problem with the if statements i would think but can't find a solution, it is meant to return either king,queen,jack or jack1 when the value of 10 is give but i only receive the value 10 in my output

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
 #include <iostream>
#include <stdlib.h>
#include <ctime>
#include <string>
using namespace std;

//calling decleration of welcome screen
void Welcome_Screen ();

//decleration of random values function
void User(int& a, int& b);
void Special_VALUES(int& c, int& d);
void ValueOfTen(int& e, int& f);
void SingleCard_Pickup(int& g, int& h);
//size of array being declared and arrys

int Array_Cards [] = {2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11};
string Suits [] = {"Clubs","Spades","Diamonds","Hearts"};
string Tens [] =  {"King","Queen","jack","jack1"};
string choice ;
int main(){

srand(time(NULL)) ;

int values = 1;
int w,x,y,z,u,v,t,s;
int total;
int cardNo = 0 ;



Welcome_Screen();

cout << "Select enter key to begin"<<endl;




User(w,x);
Special_VALUES(y,z);
ValueOfTen(u,v);
SingleCard_Pickup(t,s);

cout <<"You pick up two cards"<<endl;
cout << "Your Values are "<<endl;

if (w == 10 && x != 10){
    cout << "Card 1: " <<Tens[u] << " of " <<Suits[y] <<endl ;
    cout << "Card 2: " <<Array_Cards[x] << " of " <<Suits[z] <<endl ;
}

else if (x == 10 && w != 10){
    cout << "Card 1 : " <<Tens[v] << " of " <<Suits[z] <<endl ;
    cout << "Card 2 : " <<Array_Cards[w] << " of " <<Suits[y] <<endl ;
    }

 else if (x == 10 && w == 10){
    cout << "Card 1 : " <<Tens[u] << " of " <<Suits[z] <<endl ;
    cout << "Card 2 : " <<Tens[v] << " of " <<Suits[y] <<endl ;
}

 else if (x != 10 && w != 10) {
    cout << "Card 1 : " <<Array_Cards[w] << " of " <<Suits[y] <<endl ;
    cout << "Card 2 : " <<Array_Cards[x] << " of " <<Suits[z] <<endl ;
}

cardNo = 2;

total = Array_Cards[w] + Array_Cards[x];

cout << "Your total so far is " << total;

cout <<" Do you want to hold or hit? "<<endl;
cout <<"(Please enter either hold or hit) " <<endl;


cin >> choice ;

if (choice == "hit"){

    cardNo ++;
    cout << "You draw ";
    cout<<"Card" <<cardNo <<" : " <<Array_Cards[t]<<" of " <<Suits[s] <<endl ;

    total = total + Array_Cards[t];

    cout << "Your total so far is " << total <<endl;

    if(total <=21){

    cardNo ++;

    cout <<" Do you want to hold or hit? "<<endl;
    cout <<"(Please enter either hold or hit) " <<endl;
    cin >> choice;

    if(choice == "hit"){
    SingleCard_Pickup(t,s);
    Special_VALUES(y,z);

    cout <<"You draw" <<endl;
    cout <<"Card" <<cardNo <<" : " << Array_Cards[t] <<" of "<<Suits[y] <<endl;
    total = total + Array_Cards[t];
    cout << "Your total so far is " << total <<endl;
    }

    }

    else if (total > 21){

    cout << "You have exceeded 21, computers turn" <<endl;
    }
}


return 0;
}



 void User(int& a, int& b){

a = rand() %51 ;
b = rand() %51 ;
}

void Welcome_Screen(){
cout <<"\t\t\t******************************\t\t\t\t"<<endl;
cout <<"\t\t\t****                      ****\t\t\t\t"<<endl;
cout <<"\t\t\t*****Welcome to Blackjack*****\t\t\t\t"<<endl;
cout <<"\t\t\t****  Powered by Rnjesus  ****\t\t\t\t"<<endl;
cout <<"\t\t\t******************************\t\t\t\t"<<endl;
}

void Special_VALUES(int& c,int& d){

c  = rand()%3;
d  = rand()%3;
}

void ValueOfTen(int& e, int& f){
e  = rand()% 3;
f  = rand()% 3;
}

void SingleCard_Pickup(int& g, int& h){

g = rand() %51 ;
h = rand() %3;

}
Obviously, the code on lines 62 - 65 is being executed when you don't want it to.

1
2
3
4
 else if (x != 10 && w != 10) {
    cout << "Card 1 : " <<Array_Cards[w] << " of " <<Suits[y] <<endl ;
    cout << "Card 2 : " <<Array_Cards[x] << " of " <<Suits[z] <<endl ;
}


This is why it's important for you to give meaningful names to your variables. I can't help you because I don't know what x, w, z actually are - your code is all over the place.
Last edited on
this is why i am a beginner please continue any help i am grateful for and the code wouldn't have to be named if you looked at the calling of the function
Not 100% sure what it's supposed to do, but I get different card values when I run it.
in the terms of jack,king,queen?
You've ignored the advice to have a single function to print a card value. Doing so would simplify lines 47-65. If you're not going to follow the advice given, then there is not much point in my giving you further advice.

You still haven't explained why lines 123,134,148 are using modulo 51. You will never be able to draw the jack1 of hearts. Had you used the const here as previously suggested, that would not be an issue.

What is the difference between Special_VALUES() and ValueOfTen()? The code is identical. Why have two functions that do the same thing?

the code wouldn't have to be named if you looked at the calling of the function

Wrong. The variables names should make it obvious what they are. The reader should NOT have to refer to a called function to determine what the variables are. You should make your program easy for the reader to understand. It is not.

Topic archived. No new replies allowed.