I am busy building this black jack game, and been struggling with something...
I know its not programmed in perfect language, but i do try to only use the functions i know.
Now the problem i have is that, this part
on line 105 does not randomise everytime i use it...Code:#include<iostream> #include<stdlib> #include<time> #include<string> using namespace std; int main() { char Choice, Play; int Card1, Card2, Card3, Card4, Card5, CardTotal, PCTotal; int Cash, Bet; string Name; srand(time(0)); cout<<"\n *******************" "\n *BlackJack v0.001 *" "\n *By RHiNO *" "\n *Started 20/02/06 *" "\n *******************"<<endl; cout<<"\n\n\n"; while(true) { cout<<" WELCOME \n MAIN MENU\n"<<endl; cout<<"Please select from the following:\n"; cout<<"p: Play Game.\n"; cout<<"q: Quit.\n"; cin>>Choice; cin.ignore(); if(Choice=='q') { cout<<"Thank you for playing!"; break; } if(Choice=='p') { cout<<"You selected to start a game.\nl: Load Game. n: New Game\n"; cout<<"Choice: "; cin>>Play; if(Play=='n') { cout<<"What is your name?\n"; cin>>Name; Cash=100; } if(Play=='l') { Name="loaded name"; Cash=132; //loaded amount cin.get(); } cout<<"Hey "<<Name<<". You have R"<<Cash<<" in your pocket\n"; while(true) { if(Cash<1) { cout<<Name<<", you are bancrupt. \nGAME OVER\n"; break; } cout<<Name<<" you have R"<<Cash<<" left... \nWhat would you like to do?\n"; cout<<"p: Play. s: Save m: Main Menu\n"; cout<<"Selection: "; cin>>Choice; cin.ignore(); if(Choice=='m') { break; } if(Choice=='s') { cout<<"Feature disabled... Press enter to continue.\n"; cin.get(); continue; } if(Choice=='p') { NoMoney: cout<<"How much would you like to bet: "; cin>>Bet; if(Bet>Cash+1) { cout<<"You do not have that much money.\n"; goto NoMoney; } if(Bet<1) { cout<<"Sorry you cant bet less than R1!\n"; goto NoMoney; } if(Bet<Cash+1&&Bet>0) { Card1=1+rand()%11; Card2=1+rand()%10; Card3=1+rand()%11; Card4=1+rand()%10; Card5=1+rand()%10; Cash=Cash-Bet; CardTotal=Card1+Card2; PCTotal=Card3+Card4; cout<<Name<<" place a bet of R"<<Bet<<" and have "<<Cash<<" left\n"; cout<<Name<<" gets two cards which are "<<Card1<<" and "<<Card2<<". You have "<<CardTotal<<"\n"; cout<<"The computer gets "<<Card3<<" and "<<Card4<<". The computer has "<<PCTotal<<"\n"; if(CardTotal==21) { if(PCTotal==21) { cout<<"Its a draw.\n"; Cash=Cash+Bet; } else { cout<<"BLACKJACK "<<Name<<" wins R"<<Bet+Bet<<"!\n"; Cash=Cash+Bet+Bet+Bet; } } if(PCTotal==21) { cout<<"The computer has BLACKJACK"; } if(CardTotal<21) { while(true) { cout<<"Would you like another card?\ny: Yes n: No\n"; cin>>Choice; cin.ignore(); if(Choice=='n') { break; } if(Choice=='y') { cout<<Name<<" gets a "<<Card5<<"\n"; CardTotal=CardTotal+Card5; cout<<Name<<" got a score of "<<CardTotal<<" now.\n"; if(CardTotal>21) { cout<<Name<<" looses!!\n"; break; } continue; } } } if(PCTotal<17) { while(true) { cout<<"The computer takes another card, "<<Card5<<"!\n"; PCTotal=PCTotal+Card5; cout<<"PC now has "<<PCTotal<<" points\n"; if(PCTotal>17) { break; } if(PCTotal<17) { continue; } } } } continue; } } continue; } cout<<"Invalid choice!!\n"; } cin.get(); }
Any help icw the specific problem will be appreciated, other bugs ill try find and fix myself.
Thanks alot
PS:: How do i add attachments?



LinkBack URL
About LinkBacks


