rand().
Jun 21, 2012 at 7:12am Jun 21, 2012 at 7:12am UTC
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
#include<iostream>
#include<time.h>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
string name;
int SumOfCards;
int cards;
int player;
string choice="hit" ;
cout<<"Choose a name:" ;
getline(cin,name);
cout<<"\nHello " <<name<<",i wish to enjoy the BlackJack.\nGood luck" <<endl;
srand(time(NULL));
cards=rand()%4;
player=cards+cards;
cout<<player;
while (choice=="hit" )
{
cin>>choice;
if (choice=="hit" )
{
player=player+cards;
cout<<player;
}
else if (choice=="stay" )
{
cout<<player;
break ;
}
}
}
I am trying to make a blackjack game but i have a problem with rand().
The problem is that the card dont change value so if it give to me 6(two cards so it is 3+3),after will give me 9 after 12 ,i mean it is only 3 always.
how can change it?
Jun 21, 2012 at 7:17am Jun 21, 2012 at 7:17am UTC
Look carefully at where you are setting your cards variable.
Jun 21, 2012 at 7:27am Jun 21, 2012 at 7:27am UTC
can help me?
Jun 21, 2012 at 7:29am Jun 21, 2012 at 7:29am UTC
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
#include<iostream>
#include<time.h>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
string name;
int SumOfCards;
int cards;
int player;
string choice="hit" ;
cout<<"Choose a name:" ;
getline(cin,name);
cout<<"\nHello " <<name<<",i wish to enjoy the BlackJack.\nGood luck" <<endl;
srand(time(NULL));
cards=rand()%11;
player=cards+cards;
cout<<player;
while (choice=="hit" )
{
srand(time(NULL));
cards=rand()%11;
cin>>choice;
if (choice=="hit" )
{
player=player+cards;
cout<<player;
}
else if (choice=="stay" )
{
cout<<player;
break ;
}
}
}
Something like this?
Topic archived. No new replies allowed.