there is a questions about c++.

int main(int argc, char** argv) {
int cart1,cart2,cart3,cart4,cartotal,x;

string players[2];

{
srand(time(NULL));
string lpayers[2] = { "A player","B player" };
int x = rand() % 2;
cout << oyuncular[x]<<endl;
}
if(????){

srand(time(NULL));
cart1=1+rand()%13;
cart2=1+rand()%13;
cartotal=cart1+cart2;
cout<<"1.puan : " <<cart1<<endl;
cout<<"2.puan : "<<cart2<<endl;
}
if(??????){

srand(time(NULL));
cart1=1+rand()%13;
cart2=1+rand()%13;
cartotal=cart1+cart2;
cout<<"3.puan : " <<cart1<<endl;
cout<<"4.puan : "<<cart2<<endl;
}

}

question; after choosed random admistation, if choose is“A player”,Do this. if choose is“B player”,Do this.
do you help me ? for this,What do you wrtie inside "if(??)"?
Thanks.

I would guess that you mean:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if(0 == x){ // is“A player”,Do this
srand(time(NULL));
cart1=1+rand()%13;
cart2=1+rand()%13;
cartotal=cart1+cart2;
cout<<"1.puan : " <<cart1<<endl;
cout<<"2.puan : "<<cart2<<endl;
}
if(1 == x){ // is“B player”,Do this

srand(time(NULL));
cart1=1+rand()%13;
cart2=1+rand()%13;
cartotal=cart1+cart2;
cout<<"3.puan : " <<cart1<<endl;
cout<<"4.puan : "<<cart2<<endl;
}
Further more: srand(time(NULL)); should only be called once at the top of main. Otherwise you will repeat random numbers which means loosing the randomness.

This:
1
2
3
cart1=1+rand()%13;
cart2=1+rand()%13;
cartotal=cart1+cart2;
is the same in both if(...), hence you can move it out/before the ifs in order to void code repetition.
for example;
start program.
Then choose "A player".
I give card1 and card2.
Then
after "A player", I want to do "B player" this same.
( this program is my homework. After I must choose random either player.I Pass other player.
This is program.)
You help me.
Thanks
Topic archived. No new replies allowed.