Tuesday, July 28, 2009

Can anyony help me with my code?

I am trying to do a blackjack program in C++ and here is my code so far





#include%26lt;iostream.h%26gt;





void shuffle(int shuffle) // function prototype


{





int random_card_number;


int lowest=1, highest=13;


int range=(highest-lowest)+1;


int nArray{13};


int i; int card_numbers;


int array;





for(int i=0; i%26lt;52; i++)


{


nArray[i] = random_card_number;


}





for(int j=0; j%26lt;52 j++)


{


cout.width(4);


cout%26lt;%26lt;random_card_number%26lt;%26lt;" ";


cout.width(0);


cout%26lt;%26lt;card_numbers%26lt;%26lt;" "%26lt;%26lt;endl;


}


card_numbers++;


}





void getcard(int card_number);





int main()


{


int card_number:


int random_card_number;


int sum;





cout%26lt;%26lt;"Enter a card_number";


cin%26gt;%26gt;card_number;





sum= card_number+random_card_number;


cout%26lt;%26lt;"sum;"%26lt;%26lt;suml





if(card_number == 1)


{


cout%26lt;%26lt;"Ace%26lt;%26lt;endl;


}


if(card_number==2)


cout%26lt;%26lt;"Two"%26lt;%26lt;endl;


}


if(card_number==3)


{


cout%26lt;%26lt;"Three"%26lt;%26lt;endl;


}





Then the code just says if statements for the number for example if the card number was 3 then in my code it is three





I am trying to get this code to play out like a BJ game

Can anyony help me with my code?
Does not look easy. If you are still stuck , may be you can contact a C++ expert at websites like http://askexpert.info/
Reply:Card games are VERY complex. The best program I've made so far that acts like a casino game is...


...OK, the name escapes me. But it rolls dice. If you want blackjack, you've barely scratched the surface of the coding.


Sorry I couldn't be of more help.
Reply:Just so you know...


Using the variable random_card_number without initializing it doesn't really give you random numbers. You need to use a random number generating function. To make it really good you would need to use a true random number generator and not a pseudo-random number generator.


You could use the C functions rand or srand but these are both pseudo-random number generators.


Also, I would suggest using a map or an array for your card_number to string mapping. This would eliminate the need for 52 if statements.


No comments:

Post a Comment