When I compile this thing, I got a lot of errors. Can anyone help me with this?
I was trying to make a BlackJack game?
#include <iostream>
#include <vector>
using namespace std;
vector<int> value(1,2,3,4,5,6,7,8,9,10,10,10,10);
vector<int> value1(value,value,value,value);
class MyHand{
public:
vector<int>HandDeck();
bool Count = false;
bool WantToDraw = true;
void DrawCard(){
if (HandDeck.size()<5){
int a = rand()%52;
HandDeck.push_back(value.at(a));
}
else if (HandDeck.size()>=5){
Count = true;
}
}
int SumOfHand(){
int sum = 0;
for (unsigned i = 0;i<HandDeck.size();i++){
sum +=HandDeck[i];
}
return sum;
}
}
int main(){
MyHand myhand;
MyHand bothand;
for (int i = 1; i<=2;i++){
myhand.DrawCard();
cout <<myhand.HandDeck;
bothand.DrawCard();
}
while (true){
while (true){
char draw;
scanf("Do you want to draw card? (y or n only) %c\n",&draw);
if (draw == y){
myhand.DrawCard();
}
else if (draw == n){
myhand.WantToDraw=false;break;
}
else {
cout <<"I take it as a no.\n";
break;
}
}
while (true){
bothand.DrawCard();
if (bothand.SumOfHand()>17){bothand.WantToDraw=false;break;}
}
if ((myhand.Count==true&&bothand.Count==true)||(myhand.WantToDraw==false&&bothand.WantToDraw==false)){
break;
}
}
if (myhand.SumOfHand()<=21&&bothand.SumOfHand()<=21){
if (myhand.SumOfHand()<bothand.SumOfHand()){
cout <<"You lose. You are such a chicken.";
}
else
{
cout <<"You win. How dare you?";
}
}
else if (myhand.SumOfHand()>21&&bothand.SumOfHand()<=21) cout <<"You lose. You are such a chicken.";
else if (myhand.SumOfHand()<=21&&bothand.SumOfHand()>21) cout <<"You win. Damn it";
else
{
cout <<"Nah, you such a chicken.";
}
return 0;
}
Thank you very much.
P/S: I can’t find the right tag for my problem. It used to have right tags for problems related to other programming language than Web development.