blackjack help

its not adding the values correctly, it just shows zero every time. the code is very messy because i did it in a rush, but pelase try ad help. The problem is with the adding method.

PLEASE IGNORE THE COMMENTS


#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
//functiuon report results of game
//function continue asks user to continue after win or lose
// update how many imtes you have won or lost
//play game function
//function that randomizes cards

//EVENTUALLY SWITCH SO ONLY 4 OD EACH VALUE CANBE USED!!!

int deck[10] = {1,2,3,4,5,6,7,8,9,10};// deck with 10 values, but must have 9 + 1 to prevent 0 value...
//vector<int> dealer_cards;// to keep track of number of cards and score VECTOR ARE NOT WORKING, TRY AGAIN LATER!!!
//vector<int> user_cards;//to keep track of number oards and score VECTOR ARE NOT WORKING TRY AGAIN LATER!!!
//VECTORS VECTOR.PUSHBACK not working
int dealer_cards[11];//FIRST 0 VALE IS DUMMY VARIABLE CUZ IT ALWAYS GIVES ZERO AS VALUE!!!
int user_cards[10];
int static_count = 0;
int i;
int e;
int z;//for if statement.
int sum_user;
int sum_dealer;
int whi;
bool ifno = true;
// ACCEPT PARAMETERS BOOLEAN VALUE SET TRUE FIRST TIME AND FALCSE AFTER!!!11111
static void add_to_current_sum(int* sum_user, int* sum_dealer, int user_cards[], int dealer_cards[], bool ifno){// BYREF so it changes value directly
if (ifno == true){
for(int i = 0;i < static_count;i++){//TAKE OUT IF NOT FIXED FOR LOOP!!!!!
sum_user += user_cards[i]; sum_dealer += dealer_cards[i];
ifno = false; // TO CHANGE METHOD PROCEDURE AFTER TRUE FIRST TIME.
}}

if (ifno == false){
sum_user+= user_cards[static_count];
sum_dealer+= dealer_cards[static_count];
}
}

void get_cards(){

static_count++;

i = (rand() % 10);// why is it still giving zro values???

e = (rand() % 10);
i +=1;
dealer_cards[static_count] = deck[i];// assigns random value 1-10 from deck to dealer cards and usercards

user_cards[static_count] = deck[e];

}

int main() {

srand(unsigned(time(0)));// feeds random number generator so ir is random number generaro

cout<<"Welcome to blackjack "<<endl;
get_cards();// first one gives dummy value of zero.
get_cards();
get_cards();
cout<<"here are your cards: "<< user_cards[1]<<" and "<<user_cards[2]<<endl;
cout<<" "<<endl;
while( whi < 10000){// ..... very stupid way to do this but i didnt have alot of time.1
cout<<"1 = hit me, 2 = stop"<<endl;
cin >> z;
if (z ==1){
get_cards();

cout<<" "<<user_cards[static_count]<<endl;
if (sum_user > 21){
cout<<"you lose, your total is "<<sum_user<<endl;
break;
}
add_to_current_sum(&sum_user, &sum_dealer, user_cards,dealer_cards, ifno);

}else if(z == 2){


add_to_current_sum(&sum_user, &sum_dealer, user_cards, dealer_cards, ifno);



cout<<"you had "<<sum_user<<" points, and i had "<<sum_dealer<<" points"<<endl;

if ((sum_user > sum_dealer) && (sum_user <= 21)){
cout<<"you win !"<<endl;
}else if ((sum_dealer >= sum_user) && (sum_dealer <= 21)){//if daler is equal then he wins right?
cout<<"I win!"<<endl;
break;
break;
break;
break;
break;
}
}else{
cout<<"not a valid response"<<endl;
break;
break;
break;
break;


}

}



return 0;
}



Topic archived. No new replies allowed.