Getting a Segmentation Fault after one iteration of the loop for text-based bluff(cheat) card game [on hold]











up vote
-2
down vote

favorite












Please look into the following code for a text-based bluff(cheat)game.
it should display the cards in hand for each user before their turn.
ask for the cards they want to call, and then for the actual cards they want to
place on the pile(one by one).
then display the number and type of card which were called.
for some reason the code is giving a segmentation fault.
being a beginnner programmer, i cant understand whats wrong.



        #include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>



using namespace std;
//cardnamesvector
const vector<string> names={"","Ace Of Hearts","Two Of Hearts","Three Of Hearts","Four Of Hearts","Five Of Hearts","Six Of Hearts"
,"Seven Of Hearts","Eight Of Hearts","Nine Of Hearts","Ten Of Hearts","Jack Of Hearts","Queen Of Hearts","King Of Hearts",
"Ace Of Diamonds","Two Of Diamonds","Three Of Diamonds","Four Of Diamonds","Five Of Diamonds","Six Of Diamonds","Seven Of Diamonds",
"Eight Of Diamonds","Nine Of Diamonds","Ten Of Diamonds","Jack Of Diamonds","Queen Of Diamonds","King Of Diamonds",
"Ace Of Spades","Two Of Spades","Three Of Spades","Four Of Spades","Five Of Spades","Six Of Spades"
,"Seven Of Spades","Eight Of Spades","Nine Of Spades","Ten Of Spades","Jack Of Spades","Queen Of Spades","King Of Spades",
"Ace Of Clubs","Two Of Clubs","Three Of Clubs","Four Of Clubs","Five Of Clubs","Six Of Clubs"
,"Seven Of Clubs","Eight Of Clubs","Nine Of Clubs","Ten Of Clubs","Jack Of Clubs","Queen Of Clubs","King Of Clubs"};
//cardnumbers vector
const vector<int> numbers={0,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,50,51,52};
//return random values to fill each players hand
int shuffler(vector<int>& ex);
//fill each players hand
void cardDistributor(vector<int>&play, vector<int>&excl, int n);
//print inhand cards
void InHandPrint( vector<int>play);

//convert user input into integer for number of cards and integer for type of card
void task1(string opt, int& nfc, int&tfc);
// print the type and number of cards called
void task2(int nfc, int tfc);
//determine whether a user passed their turn
void pass(vector<int>pile,vector<bool>pval,int n);
// the actual game, populating the pile, unpopulating the hand and so on
void task3(int nfc1, int tfc1, int nfc2, int tfc2, int nfc3, int tfc3, int nfc4,int tfc4,vector<int>&play1,vector<int>&play2, vector<int>&pile,vector<bool>&pval, int nofturns, int totp, int ctofc);
// check for bluff
void bluffcheck(vector<int>&play1,vector<int>&play2,vector<int>pile, int nofturns, int totp, int ctofc);
//interface to the game
int game(vector<int>&play1,vector<int>& play2);

int main(){
srand(time(NULL));
vector<int>play1;//handplayer1
vector<int>play2;//handplayer2
vector<int>exc;//vector so that numbers are not repeated during shuffling
cardDistributor(play1,exc, 1);//distribution of cards to player 1
cardDistributor(play2,exc, 2);//distribution of cards to player 2
cout<<"Welcome"<<endl;
game(play1,play2);

}

int game(vector<int>&play1,vector<int>& play2){
string Toptions1; string Toptions2;//strings to take actual card input
string Coptions1; string Coptions2;//strings to take called cards input
vector<int> pile;//pile vector
int Tnofc1; int Ttofc1; int Tnofc2; int Ttofc2; int Tnofc3; int Ttofc3; int Tnofc4; int Ttofc4;
//^^ints to keep track of cards entered
int totalp1;
int totalp2;
int Cnofc1=0; int Ctofc1=0;
int Cnofc2=0; int Ctofc2=0;
vector<bool> passv={false,false};
int noofturns=2;
int c=1;

while(c==1){
if(noofturns%2==0){
InHandPrint(play1);
totalp1=0;
noofturns++;
getline(cin,Coptions1);
cout<<endl<<Coptions1;

task1(Coptions1, Cnofc1, Ctofc1);


getline(cin,Toptions1);

task1(Toptions1,Tnofc1,Ttofc1);

getline(cin,Toptions1);


task1(Toptions1,Tnofc2,Ttofc2);

getline(cin,Toptions1);
task1(Toptions1,Tnofc3,Ttofc3);

getline(cin,Toptions1);


task1(Toptions1,Tnofc4,Ttofc4);
task2(Cnofc1, Ctofc1);


totalp1=totalp1+Tnofc1+Tnofc2+Tnofc3+Tnofc4;
task3(Tnofc1,Ttofc1,Tnofc2,Ttofc2,Tnofc3,Ttofc3,Tnofc4,Ttofc4, play1, play2, pile, passv, noofturns,totalp2,Ctofc2);
cin.get();}
else if(noofturns%2==1){
InHandPrint(play2);
totalp2=0;
noofturns++;
getline(cin,Coptions2);
task1(Coptions2, Cnofc2, Ctofc2);

cout<<"done"<<endl;

getline(cin,Toptions2);
task1(Toptions2,Tnofc1,Ttofc1);
cout<<"done"<<endl;
getline(cin,Toptions2);
task1(Toptions2,Tnofc2,Ttofc2);

cout<<"done"<<endl;
getline(cin,Toptions2);
task1(Toptions2,Tnofc3,Ttofc3);

cout<<"done"<<endl;
getline(cin,Toptions2);

task1(Toptions2,Tnofc4,Ttofc4);
cout<<Cnofc2<<Ctofc2<<endl;
task2(Cnofc2, Ctofc2);

cout<<"done"<<endl;
totalp2=totalp2+Tnofc1+Tnofc2+Tnofc3+Tnofc4;


task3(Tnofc1,Ttofc1,Tnofc2,Ttofc2,Tnofc3,Ttofc3,Tnofc4,Ttofc4, play2, play1, pile, passv, noofturns, totalp1, Ctofc1);
cin.get();
}
}}
void bluffcheck(vector<int>&play1,vector<int>&play2,vector<int>pile, int nofturns, int totp, int ctofc){
vector<int>last4;
bool blufft=false;
for(int t=0;t<totp;t++){
last4.push_back(pile[pile.size()-(t+1)]);

}
sort(last4.begin(),last4.end());
int a=last4[0];
for(int i=0;i<totp;i++){

if((last4[i]-ctofc)%13==0){

blufft=false;
}else{blufft=true;break;}
}
if(blufft==true){

cout<<"bluff right"<<endl;
nofturns--;
int pilesize=pile.size();
for(int i=0;i<pilesize;i++){

play2.push_back(pile[i]);

}
pile.clear();

}else if(blufft==false){

cout<<"bluff wrong"<<endl;
for(int i=0;i<pile.size();i++){

play1.push_back(pile[i]);
}
pile.clear();
}

}

void pass(vector<int>pile,vector<bool>pval,int n){
pval[n-1]=true;
if(pval[0]&&pval[1]){
pile.clear();

}
}

void task3(int nfc1, int tfc1, int nfc2, int tfc2, int nfc3, int tfc3, int nfc4,int tfc4, vector<int>&play1,vector<int>&play2, vector<int>&pile,vector<bool>&pval, int nofturns, int totp, int ctofc){
int totalnfc=nfc1+nfc2+nfc3+nfc4;
int arrtfc[4]={tfc1,tfc2,tfc3,tfc4};
if(nfc1==14&&tfc1==15){
int n;
if(play1[0]==1){
n=1;
}else if(play1[0]==2){
n=2;
}
pass(pile,pval,n);
}else if(nfc1==16&&tfc1==17){
bluffcheck(play1,play2,pile,nofturns,totp,ctofc );

}
else{

for(int q=1;q<=totalnfc;q++){
for(int a=1;a<=play1.size();a++){
for(int i=arrtfc[q];i<=(39+arrtfc[q]);i=i+13){
if(play1[a]==numbers[i]){
pile.push_back(numbers[i]);
int temp=play1[play1.size()-1];

play1[a]=temp;
play1.pop_back();
}}
}}



}

}
void task2(int nnfc, int ttfc){
if(nnfc==14&&ttfc==15){
cout<<"turn Passed"<<endl;
}else if(nnfc==16&&ttfc==17){
cout<<"bluff Called"<<endl;
}else{ cout<<endl<<nnfc<<endl;
switch (nnfc){

case 1:
cout<<"one";
break;
case 2:
cout<<"two";
break;
case 3:
cout<<"three";
break;
case 4:
cout<<"four";
break;
default:
break;
}
switch(ttfc){

case 1:
cout<<" Ace(s)"<<endl;
break;
case 2:
cout<<" Two(s)"<<endl;
break;
case 3:
cout<<" Three(s)"<<endl;
break;
case 4:
cout<<" Four(s)"<<endl;
break;
case 5:
cout<<" Five(s)"<<endl;
break;
case 6:
cout<<" Six(es)"<<endl;
break;
case 7:
cout<<" Seven(s)"<<endl;
break;
case 8:
cout<<" Eight(s)"<<endl;
break;
case 9:
cout<<" Nine(s)"<<endl;
break;
case 10:
cout<<" Ten(s)"<<endl;
break;
case 11:
cout<<" Jack(s)"<<endl;
break;
case 12:
cout<<" Queen(s)"<<endl;
break;
case 13:
cout<<" King(s)"<<endl;
break;
default:
break;
}


}
}

void task1(string opt, int& nfc, int&tfc){

if(opt.size()==1){
switch (opt[0]){
case '0':
nfc=0;
tfc=0;
break;
case 'p':
nfc=14;
tfc=15;
break;
case 'b':
nfc=16;
tfc=17;
break;
default:
break;
}
}
else if(opt.size()>1){ cout<<"started"<<endl;


switch (opt[0]){

case '1':
nfc=1;
break;
case '2':
nfc=2;
break;
case '3':
nfc=3;
cout<<nfc<<endl;
break;
case '4':
nfc=4;
break;
default:
break;
}

switch (opt[2]){
case '1':
tfc=1;
break;
case '2':
tfc=2;
break;
case '3':
tfc=3;
break;
case '4':
tfc=4;
break;
case '5':
tfc=5;
break;
case '6':
tfc=6;
break;
case '7':
tfc=7;
break;
case '8':
tfc=8;
break;
case '9':
tfc=9;
break;
}

if(opt.size()==4){
switch(opt[3]){
case '0':
tfc=10;
case '1':
tfc=11;
case '2':
tfc=12;
case '3':
tfc=13;
}

}
cout<<"ended"<<endl;

}}
void InHandPrint( vector<int>play){
cout<<flush;
system("CLS");
cout<<play[0]<<endl;
cout<<"{ ";
for(int i=1;i<=26;i++){
cout<<names[play[i]]<<", ";
if(i%3==0){
cout<<endl;
}}
cout<<" }"<<flush;
}
void cardDistributor(vector<int>&play,vector<int>&excl, int n){
for(int a=0;a<=26;a++){
if(a<26){
play.push_back(shuffler(excl));}
if(a==26){

play.push_back(n);
int temp;
temp=play[0];
play[0]=play[26];
play[26]=temp;
}
}}
int shuffler(vector<int> &ex){
int n=0;
n= rand()%(52-1 + 1) + 1;
bool b=false;
if(ex.size()==0){

ex.push_back(n);
return n;
}else if(ex.size()>=1){
for(int i=0;i<ex.size();i++){

if(ex[i]!=n){

b=true;

}else if (ex[i]==n){

b=false;
break;

}


}
if(b==true){

ex.push_back(n);
return n;
}else if (b==false){

return shuffler(ex);
}

}

}









share|improve this question







New contributor




rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by tinstaafl, πάντα ῥεῖ, Incomputable, Edward, Mathias Ettinger 14 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – tinstaafl, πάντα ῥεῖ, Incomputable, Edward, Mathias Ettinger

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    Code not working as intended is not ready for review and off topic on Code Review. Looks on-topic in SO - heed item 1 spelling out how to get debugging support on SO.
    – greybeard
    14 hours ago










  • Even on SO that's way to big. You need to do some work in trying to narrow down the problem. Also if you want people to help you should fix the formatting. There is nothing more annoying than trying to read badly formatted code. To make it easy to copy and paste remove all tabs from your source (your IDE should be able to do it) and then get your IDE to do standard formatting. Then copy and paste that. the 'button' marked '{}' in the edit window will then add the indentation required for you.
    – Martin York
    7 hours ago















up vote
-2
down vote

favorite












Please look into the following code for a text-based bluff(cheat)game.
it should display the cards in hand for each user before their turn.
ask for the cards they want to call, and then for the actual cards they want to
place on the pile(one by one).
then display the number and type of card which were called.
for some reason the code is giving a segmentation fault.
being a beginnner programmer, i cant understand whats wrong.



        #include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>



using namespace std;
//cardnamesvector
const vector<string> names={"","Ace Of Hearts","Two Of Hearts","Three Of Hearts","Four Of Hearts","Five Of Hearts","Six Of Hearts"
,"Seven Of Hearts","Eight Of Hearts","Nine Of Hearts","Ten Of Hearts","Jack Of Hearts","Queen Of Hearts","King Of Hearts",
"Ace Of Diamonds","Two Of Diamonds","Three Of Diamonds","Four Of Diamonds","Five Of Diamonds","Six Of Diamonds","Seven Of Diamonds",
"Eight Of Diamonds","Nine Of Diamonds","Ten Of Diamonds","Jack Of Diamonds","Queen Of Diamonds","King Of Diamonds",
"Ace Of Spades","Two Of Spades","Three Of Spades","Four Of Spades","Five Of Spades","Six Of Spades"
,"Seven Of Spades","Eight Of Spades","Nine Of Spades","Ten Of Spades","Jack Of Spades","Queen Of Spades","King Of Spades",
"Ace Of Clubs","Two Of Clubs","Three Of Clubs","Four Of Clubs","Five Of Clubs","Six Of Clubs"
,"Seven Of Clubs","Eight Of Clubs","Nine Of Clubs","Ten Of Clubs","Jack Of Clubs","Queen Of Clubs","King Of Clubs"};
//cardnumbers vector
const vector<int> numbers={0,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,50,51,52};
//return random values to fill each players hand
int shuffler(vector<int>& ex);
//fill each players hand
void cardDistributor(vector<int>&play, vector<int>&excl, int n);
//print inhand cards
void InHandPrint( vector<int>play);

//convert user input into integer for number of cards and integer for type of card
void task1(string opt, int& nfc, int&tfc);
// print the type and number of cards called
void task2(int nfc, int tfc);
//determine whether a user passed their turn
void pass(vector<int>pile,vector<bool>pval,int n);
// the actual game, populating the pile, unpopulating the hand and so on
void task3(int nfc1, int tfc1, int nfc2, int tfc2, int nfc3, int tfc3, int nfc4,int tfc4,vector<int>&play1,vector<int>&play2, vector<int>&pile,vector<bool>&pval, int nofturns, int totp, int ctofc);
// check for bluff
void bluffcheck(vector<int>&play1,vector<int>&play2,vector<int>pile, int nofturns, int totp, int ctofc);
//interface to the game
int game(vector<int>&play1,vector<int>& play2);

int main(){
srand(time(NULL));
vector<int>play1;//handplayer1
vector<int>play2;//handplayer2
vector<int>exc;//vector so that numbers are not repeated during shuffling
cardDistributor(play1,exc, 1);//distribution of cards to player 1
cardDistributor(play2,exc, 2);//distribution of cards to player 2
cout<<"Welcome"<<endl;
game(play1,play2);

}

int game(vector<int>&play1,vector<int>& play2){
string Toptions1; string Toptions2;//strings to take actual card input
string Coptions1; string Coptions2;//strings to take called cards input
vector<int> pile;//pile vector
int Tnofc1; int Ttofc1; int Tnofc2; int Ttofc2; int Tnofc3; int Ttofc3; int Tnofc4; int Ttofc4;
//^^ints to keep track of cards entered
int totalp1;
int totalp2;
int Cnofc1=0; int Ctofc1=0;
int Cnofc2=0; int Ctofc2=0;
vector<bool> passv={false,false};
int noofturns=2;
int c=1;

while(c==1){
if(noofturns%2==0){
InHandPrint(play1);
totalp1=0;
noofturns++;
getline(cin,Coptions1);
cout<<endl<<Coptions1;

task1(Coptions1, Cnofc1, Ctofc1);


getline(cin,Toptions1);

task1(Toptions1,Tnofc1,Ttofc1);

getline(cin,Toptions1);


task1(Toptions1,Tnofc2,Ttofc2);

getline(cin,Toptions1);
task1(Toptions1,Tnofc3,Ttofc3);

getline(cin,Toptions1);


task1(Toptions1,Tnofc4,Ttofc4);
task2(Cnofc1, Ctofc1);


totalp1=totalp1+Tnofc1+Tnofc2+Tnofc3+Tnofc4;
task3(Tnofc1,Ttofc1,Tnofc2,Ttofc2,Tnofc3,Ttofc3,Tnofc4,Ttofc4, play1, play2, pile, passv, noofturns,totalp2,Ctofc2);
cin.get();}
else if(noofturns%2==1){
InHandPrint(play2);
totalp2=0;
noofturns++;
getline(cin,Coptions2);
task1(Coptions2, Cnofc2, Ctofc2);

cout<<"done"<<endl;

getline(cin,Toptions2);
task1(Toptions2,Tnofc1,Ttofc1);
cout<<"done"<<endl;
getline(cin,Toptions2);
task1(Toptions2,Tnofc2,Ttofc2);

cout<<"done"<<endl;
getline(cin,Toptions2);
task1(Toptions2,Tnofc3,Ttofc3);

cout<<"done"<<endl;
getline(cin,Toptions2);

task1(Toptions2,Tnofc4,Ttofc4);
cout<<Cnofc2<<Ctofc2<<endl;
task2(Cnofc2, Ctofc2);

cout<<"done"<<endl;
totalp2=totalp2+Tnofc1+Tnofc2+Tnofc3+Tnofc4;


task3(Tnofc1,Ttofc1,Tnofc2,Ttofc2,Tnofc3,Ttofc3,Tnofc4,Ttofc4, play2, play1, pile, passv, noofturns, totalp1, Ctofc1);
cin.get();
}
}}
void bluffcheck(vector<int>&play1,vector<int>&play2,vector<int>pile, int nofturns, int totp, int ctofc){
vector<int>last4;
bool blufft=false;
for(int t=0;t<totp;t++){
last4.push_back(pile[pile.size()-(t+1)]);

}
sort(last4.begin(),last4.end());
int a=last4[0];
for(int i=0;i<totp;i++){

if((last4[i]-ctofc)%13==0){

blufft=false;
}else{blufft=true;break;}
}
if(blufft==true){

cout<<"bluff right"<<endl;
nofturns--;
int pilesize=pile.size();
for(int i=0;i<pilesize;i++){

play2.push_back(pile[i]);

}
pile.clear();

}else if(blufft==false){

cout<<"bluff wrong"<<endl;
for(int i=0;i<pile.size();i++){

play1.push_back(pile[i]);
}
pile.clear();
}

}

void pass(vector<int>pile,vector<bool>pval,int n){
pval[n-1]=true;
if(pval[0]&&pval[1]){
pile.clear();

}
}

void task3(int nfc1, int tfc1, int nfc2, int tfc2, int nfc3, int tfc3, int nfc4,int tfc4, vector<int>&play1,vector<int>&play2, vector<int>&pile,vector<bool>&pval, int nofturns, int totp, int ctofc){
int totalnfc=nfc1+nfc2+nfc3+nfc4;
int arrtfc[4]={tfc1,tfc2,tfc3,tfc4};
if(nfc1==14&&tfc1==15){
int n;
if(play1[0]==1){
n=1;
}else if(play1[0]==2){
n=2;
}
pass(pile,pval,n);
}else if(nfc1==16&&tfc1==17){
bluffcheck(play1,play2,pile,nofturns,totp,ctofc );

}
else{

for(int q=1;q<=totalnfc;q++){
for(int a=1;a<=play1.size();a++){
for(int i=arrtfc[q];i<=(39+arrtfc[q]);i=i+13){
if(play1[a]==numbers[i]){
pile.push_back(numbers[i]);
int temp=play1[play1.size()-1];

play1[a]=temp;
play1.pop_back();
}}
}}



}

}
void task2(int nnfc, int ttfc){
if(nnfc==14&&ttfc==15){
cout<<"turn Passed"<<endl;
}else if(nnfc==16&&ttfc==17){
cout<<"bluff Called"<<endl;
}else{ cout<<endl<<nnfc<<endl;
switch (nnfc){

case 1:
cout<<"one";
break;
case 2:
cout<<"two";
break;
case 3:
cout<<"three";
break;
case 4:
cout<<"four";
break;
default:
break;
}
switch(ttfc){

case 1:
cout<<" Ace(s)"<<endl;
break;
case 2:
cout<<" Two(s)"<<endl;
break;
case 3:
cout<<" Three(s)"<<endl;
break;
case 4:
cout<<" Four(s)"<<endl;
break;
case 5:
cout<<" Five(s)"<<endl;
break;
case 6:
cout<<" Six(es)"<<endl;
break;
case 7:
cout<<" Seven(s)"<<endl;
break;
case 8:
cout<<" Eight(s)"<<endl;
break;
case 9:
cout<<" Nine(s)"<<endl;
break;
case 10:
cout<<" Ten(s)"<<endl;
break;
case 11:
cout<<" Jack(s)"<<endl;
break;
case 12:
cout<<" Queen(s)"<<endl;
break;
case 13:
cout<<" King(s)"<<endl;
break;
default:
break;
}


}
}

void task1(string opt, int& nfc, int&tfc){

if(opt.size()==1){
switch (opt[0]){
case '0':
nfc=0;
tfc=0;
break;
case 'p':
nfc=14;
tfc=15;
break;
case 'b':
nfc=16;
tfc=17;
break;
default:
break;
}
}
else if(opt.size()>1){ cout<<"started"<<endl;


switch (opt[0]){

case '1':
nfc=1;
break;
case '2':
nfc=2;
break;
case '3':
nfc=3;
cout<<nfc<<endl;
break;
case '4':
nfc=4;
break;
default:
break;
}

switch (opt[2]){
case '1':
tfc=1;
break;
case '2':
tfc=2;
break;
case '3':
tfc=3;
break;
case '4':
tfc=4;
break;
case '5':
tfc=5;
break;
case '6':
tfc=6;
break;
case '7':
tfc=7;
break;
case '8':
tfc=8;
break;
case '9':
tfc=9;
break;
}

if(opt.size()==4){
switch(opt[3]){
case '0':
tfc=10;
case '1':
tfc=11;
case '2':
tfc=12;
case '3':
tfc=13;
}

}
cout<<"ended"<<endl;

}}
void InHandPrint( vector<int>play){
cout<<flush;
system("CLS");
cout<<play[0]<<endl;
cout<<"{ ";
for(int i=1;i<=26;i++){
cout<<names[play[i]]<<", ";
if(i%3==0){
cout<<endl;
}}
cout<<" }"<<flush;
}
void cardDistributor(vector<int>&play,vector<int>&excl, int n){
for(int a=0;a<=26;a++){
if(a<26){
play.push_back(shuffler(excl));}
if(a==26){

play.push_back(n);
int temp;
temp=play[0];
play[0]=play[26];
play[26]=temp;
}
}}
int shuffler(vector<int> &ex){
int n=0;
n= rand()%(52-1 + 1) + 1;
bool b=false;
if(ex.size()==0){

ex.push_back(n);
return n;
}else if(ex.size()>=1){
for(int i=0;i<ex.size();i++){

if(ex[i]!=n){

b=true;

}else if (ex[i]==n){

b=false;
break;

}


}
if(b==true){

ex.push_back(n);
return n;
}else if (b==false){

return shuffler(ex);
}

}

}









share|improve this question







New contributor




rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by tinstaafl, πάντα ῥεῖ, Incomputable, Edward, Mathias Ettinger 14 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – tinstaafl, πάντα ῥεῖ, Incomputable, Edward, Mathias Ettinger

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    Code not working as intended is not ready for review and off topic on Code Review. Looks on-topic in SO - heed item 1 spelling out how to get debugging support on SO.
    – greybeard
    14 hours ago










  • Even on SO that's way to big. You need to do some work in trying to narrow down the problem. Also if you want people to help you should fix the formatting. There is nothing more annoying than trying to read badly formatted code. To make it easy to copy and paste remove all tabs from your source (your IDE should be able to do it) and then get your IDE to do standard formatting. Then copy and paste that. the 'button' marked '{}' in the edit window will then add the indentation required for you.
    – Martin York
    7 hours ago













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











Please look into the following code for a text-based bluff(cheat)game.
it should display the cards in hand for each user before their turn.
ask for the cards they want to call, and then for the actual cards they want to
place on the pile(one by one).
then display the number and type of card which were called.
for some reason the code is giving a segmentation fault.
being a beginnner programmer, i cant understand whats wrong.



        #include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>



using namespace std;
//cardnamesvector
const vector<string> names={"","Ace Of Hearts","Two Of Hearts","Three Of Hearts","Four Of Hearts","Five Of Hearts","Six Of Hearts"
,"Seven Of Hearts","Eight Of Hearts","Nine Of Hearts","Ten Of Hearts","Jack Of Hearts","Queen Of Hearts","King Of Hearts",
"Ace Of Diamonds","Two Of Diamonds","Three Of Diamonds","Four Of Diamonds","Five Of Diamonds","Six Of Diamonds","Seven Of Diamonds",
"Eight Of Diamonds","Nine Of Diamonds","Ten Of Diamonds","Jack Of Diamonds","Queen Of Diamonds","King Of Diamonds",
"Ace Of Spades","Two Of Spades","Three Of Spades","Four Of Spades","Five Of Spades","Six Of Spades"
,"Seven Of Spades","Eight Of Spades","Nine Of Spades","Ten Of Spades","Jack Of Spades","Queen Of Spades","King Of Spades",
"Ace Of Clubs","Two Of Clubs","Three Of Clubs","Four Of Clubs","Five Of Clubs","Six Of Clubs"
,"Seven Of Clubs","Eight Of Clubs","Nine Of Clubs","Ten Of Clubs","Jack Of Clubs","Queen Of Clubs","King Of Clubs"};
//cardnumbers vector
const vector<int> numbers={0,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,50,51,52};
//return random values to fill each players hand
int shuffler(vector<int>& ex);
//fill each players hand
void cardDistributor(vector<int>&play, vector<int>&excl, int n);
//print inhand cards
void InHandPrint( vector<int>play);

//convert user input into integer for number of cards and integer for type of card
void task1(string opt, int& nfc, int&tfc);
// print the type and number of cards called
void task2(int nfc, int tfc);
//determine whether a user passed their turn
void pass(vector<int>pile,vector<bool>pval,int n);
// the actual game, populating the pile, unpopulating the hand and so on
void task3(int nfc1, int tfc1, int nfc2, int tfc2, int nfc3, int tfc3, int nfc4,int tfc4,vector<int>&play1,vector<int>&play2, vector<int>&pile,vector<bool>&pval, int nofturns, int totp, int ctofc);
// check for bluff
void bluffcheck(vector<int>&play1,vector<int>&play2,vector<int>pile, int nofturns, int totp, int ctofc);
//interface to the game
int game(vector<int>&play1,vector<int>& play2);

int main(){
srand(time(NULL));
vector<int>play1;//handplayer1
vector<int>play2;//handplayer2
vector<int>exc;//vector so that numbers are not repeated during shuffling
cardDistributor(play1,exc, 1);//distribution of cards to player 1
cardDistributor(play2,exc, 2);//distribution of cards to player 2
cout<<"Welcome"<<endl;
game(play1,play2);

}

int game(vector<int>&play1,vector<int>& play2){
string Toptions1; string Toptions2;//strings to take actual card input
string Coptions1; string Coptions2;//strings to take called cards input
vector<int> pile;//pile vector
int Tnofc1; int Ttofc1; int Tnofc2; int Ttofc2; int Tnofc3; int Ttofc3; int Tnofc4; int Ttofc4;
//^^ints to keep track of cards entered
int totalp1;
int totalp2;
int Cnofc1=0; int Ctofc1=0;
int Cnofc2=0; int Ctofc2=0;
vector<bool> passv={false,false};
int noofturns=2;
int c=1;

while(c==1){
if(noofturns%2==0){
InHandPrint(play1);
totalp1=0;
noofturns++;
getline(cin,Coptions1);
cout<<endl<<Coptions1;

task1(Coptions1, Cnofc1, Ctofc1);


getline(cin,Toptions1);

task1(Toptions1,Tnofc1,Ttofc1);

getline(cin,Toptions1);


task1(Toptions1,Tnofc2,Ttofc2);

getline(cin,Toptions1);
task1(Toptions1,Tnofc3,Ttofc3);

getline(cin,Toptions1);


task1(Toptions1,Tnofc4,Ttofc4);
task2(Cnofc1, Ctofc1);


totalp1=totalp1+Tnofc1+Tnofc2+Tnofc3+Tnofc4;
task3(Tnofc1,Ttofc1,Tnofc2,Ttofc2,Tnofc3,Ttofc3,Tnofc4,Ttofc4, play1, play2, pile, passv, noofturns,totalp2,Ctofc2);
cin.get();}
else if(noofturns%2==1){
InHandPrint(play2);
totalp2=0;
noofturns++;
getline(cin,Coptions2);
task1(Coptions2, Cnofc2, Ctofc2);

cout<<"done"<<endl;

getline(cin,Toptions2);
task1(Toptions2,Tnofc1,Ttofc1);
cout<<"done"<<endl;
getline(cin,Toptions2);
task1(Toptions2,Tnofc2,Ttofc2);

cout<<"done"<<endl;
getline(cin,Toptions2);
task1(Toptions2,Tnofc3,Ttofc3);

cout<<"done"<<endl;
getline(cin,Toptions2);

task1(Toptions2,Tnofc4,Ttofc4);
cout<<Cnofc2<<Ctofc2<<endl;
task2(Cnofc2, Ctofc2);

cout<<"done"<<endl;
totalp2=totalp2+Tnofc1+Tnofc2+Tnofc3+Tnofc4;


task3(Tnofc1,Ttofc1,Tnofc2,Ttofc2,Tnofc3,Ttofc3,Tnofc4,Ttofc4, play2, play1, pile, passv, noofturns, totalp1, Ctofc1);
cin.get();
}
}}
void bluffcheck(vector<int>&play1,vector<int>&play2,vector<int>pile, int nofturns, int totp, int ctofc){
vector<int>last4;
bool blufft=false;
for(int t=0;t<totp;t++){
last4.push_back(pile[pile.size()-(t+1)]);

}
sort(last4.begin(),last4.end());
int a=last4[0];
for(int i=0;i<totp;i++){

if((last4[i]-ctofc)%13==0){

blufft=false;
}else{blufft=true;break;}
}
if(blufft==true){

cout<<"bluff right"<<endl;
nofturns--;
int pilesize=pile.size();
for(int i=0;i<pilesize;i++){

play2.push_back(pile[i]);

}
pile.clear();

}else if(blufft==false){

cout<<"bluff wrong"<<endl;
for(int i=0;i<pile.size();i++){

play1.push_back(pile[i]);
}
pile.clear();
}

}

void pass(vector<int>pile,vector<bool>pval,int n){
pval[n-1]=true;
if(pval[0]&&pval[1]){
pile.clear();

}
}

void task3(int nfc1, int tfc1, int nfc2, int tfc2, int nfc3, int tfc3, int nfc4,int tfc4, vector<int>&play1,vector<int>&play2, vector<int>&pile,vector<bool>&pval, int nofturns, int totp, int ctofc){
int totalnfc=nfc1+nfc2+nfc3+nfc4;
int arrtfc[4]={tfc1,tfc2,tfc3,tfc4};
if(nfc1==14&&tfc1==15){
int n;
if(play1[0]==1){
n=1;
}else if(play1[0]==2){
n=2;
}
pass(pile,pval,n);
}else if(nfc1==16&&tfc1==17){
bluffcheck(play1,play2,pile,nofturns,totp,ctofc );

}
else{

for(int q=1;q<=totalnfc;q++){
for(int a=1;a<=play1.size();a++){
for(int i=arrtfc[q];i<=(39+arrtfc[q]);i=i+13){
if(play1[a]==numbers[i]){
pile.push_back(numbers[i]);
int temp=play1[play1.size()-1];

play1[a]=temp;
play1.pop_back();
}}
}}



}

}
void task2(int nnfc, int ttfc){
if(nnfc==14&&ttfc==15){
cout<<"turn Passed"<<endl;
}else if(nnfc==16&&ttfc==17){
cout<<"bluff Called"<<endl;
}else{ cout<<endl<<nnfc<<endl;
switch (nnfc){

case 1:
cout<<"one";
break;
case 2:
cout<<"two";
break;
case 3:
cout<<"three";
break;
case 4:
cout<<"four";
break;
default:
break;
}
switch(ttfc){

case 1:
cout<<" Ace(s)"<<endl;
break;
case 2:
cout<<" Two(s)"<<endl;
break;
case 3:
cout<<" Three(s)"<<endl;
break;
case 4:
cout<<" Four(s)"<<endl;
break;
case 5:
cout<<" Five(s)"<<endl;
break;
case 6:
cout<<" Six(es)"<<endl;
break;
case 7:
cout<<" Seven(s)"<<endl;
break;
case 8:
cout<<" Eight(s)"<<endl;
break;
case 9:
cout<<" Nine(s)"<<endl;
break;
case 10:
cout<<" Ten(s)"<<endl;
break;
case 11:
cout<<" Jack(s)"<<endl;
break;
case 12:
cout<<" Queen(s)"<<endl;
break;
case 13:
cout<<" King(s)"<<endl;
break;
default:
break;
}


}
}

void task1(string opt, int& nfc, int&tfc){

if(opt.size()==1){
switch (opt[0]){
case '0':
nfc=0;
tfc=0;
break;
case 'p':
nfc=14;
tfc=15;
break;
case 'b':
nfc=16;
tfc=17;
break;
default:
break;
}
}
else if(opt.size()>1){ cout<<"started"<<endl;


switch (opt[0]){

case '1':
nfc=1;
break;
case '2':
nfc=2;
break;
case '3':
nfc=3;
cout<<nfc<<endl;
break;
case '4':
nfc=4;
break;
default:
break;
}

switch (opt[2]){
case '1':
tfc=1;
break;
case '2':
tfc=2;
break;
case '3':
tfc=3;
break;
case '4':
tfc=4;
break;
case '5':
tfc=5;
break;
case '6':
tfc=6;
break;
case '7':
tfc=7;
break;
case '8':
tfc=8;
break;
case '9':
tfc=9;
break;
}

if(opt.size()==4){
switch(opt[3]){
case '0':
tfc=10;
case '1':
tfc=11;
case '2':
tfc=12;
case '3':
tfc=13;
}

}
cout<<"ended"<<endl;

}}
void InHandPrint( vector<int>play){
cout<<flush;
system("CLS");
cout<<play[0]<<endl;
cout<<"{ ";
for(int i=1;i<=26;i++){
cout<<names[play[i]]<<", ";
if(i%3==0){
cout<<endl;
}}
cout<<" }"<<flush;
}
void cardDistributor(vector<int>&play,vector<int>&excl, int n){
for(int a=0;a<=26;a++){
if(a<26){
play.push_back(shuffler(excl));}
if(a==26){

play.push_back(n);
int temp;
temp=play[0];
play[0]=play[26];
play[26]=temp;
}
}}
int shuffler(vector<int> &ex){
int n=0;
n= rand()%(52-1 + 1) + 1;
bool b=false;
if(ex.size()==0){

ex.push_back(n);
return n;
}else if(ex.size()>=1){
for(int i=0;i<ex.size();i++){

if(ex[i]!=n){

b=true;

}else if (ex[i]==n){

b=false;
break;

}


}
if(b==true){

ex.push_back(n);
return n;
}else if (b==false){

return shuffler(ex);
}

}

}









share|improve this question







New contributor




rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Please look into the following code for a text-based bluff(cheat)game.
it should display the cards in hand for each user before their turn.
ask for the cards they want to call, and then for the actual cards they want to
place on the pile(one by one).
then display the number and type of card which were called.
for some reason the code is giving a segmentation fault.
being a beginnner programmer, i cant understand whats wrong.



        #include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>



using namespace std;
//cardnamesvector
const vector<string> names={"","Ace Of Hearts","Two Of Hearts","Three Of Hearts","Four Of Hearts","Five Of Hearts","Six Of Hearts"
,"Seven Of Hearts","Eight Of Hearts","Nine Of Hearts","Ten Of Hearts","Jack Of Hearts","Queen Of Hearts","King Of Hearts",
"Ace Of Diamonds","Two Of Diamonds","Three Of Diamonds","Four Of Diamonds","Five Of Diamonds","Six Of Diamonds","Seven Of Diamonds",
"Eight Of Diamonds","Nine Of Diamonds","Ten Of Diamonds","Jack Of Diamonds","Queen Of Diamonds","King Of Diamonds",
"Ace Of Spades","Two Of Spades","Three Of Spades","Four Of Spades","Five Of Spades","Six Of Spades"
,"Seven Of Spades","Eight Of Spades","Nine Of Spades","Ten Of Spades","Jack Of Spades","Queen Of Spades","King Of Spades",
"Ace Of Clubs","Two Of Clubs","Three Of Clubs","Four Of Clubs","Five Of Clubs","Six Of Clubs"
,"Seven Of Clubs","Eight Of Clubs","Nine Of Clubs","Ten Of Clubs","Jack Of Clubs","Queen Of Clubs","King Of Clubs"};
//cardnumbers vector
const vector<int> numbers={0,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,50,51,52};
//return random values to fill each players hand
int shuffler(vector<int>& ex);
//fill each players hand
void cardDistributor(vector<int>&play, vector<int>&excl, int n);
//print inhand cards
void InHandPrint( vector<int>play);

//convert user input into integer for number of cards and integer for type of card
void task1(string opt, int& nfc, int&tfc);
// print the type and number of cards called
void task2(int nfc, int tfc);
//determine whether a user passed their turn
void pass(vector<int>pile,vector<bool>pval,int n);
// the actual game, populating the pile, unpopulating the hand and so on
void task3(int nfc1, int tfc1, int nfc2, int tfc2, int nfc3, int tfc3, int nfc4,int tfc4,vector<int>&play1,vector<int>&play2, vector<int>&pile,vector<bool>&pval, int nofturns, int totp, int ctofc);
// check for bluff
void bluffcheck(vector<int>&play1,vector<int>&play2,vector<int>pile, int nofturns, int totp, int ctofc);
//interface to the game
int game(vector<int>&play1,vector<int>& play2);

int main(){
srand(time(NULL));
vector<int>play1;//handplayer1
vector<int>play2;//handplayer2
vector<int>exc;//vector so that numbers are not repeated during shuffling
cardDistributor(play1,exc, 1);//distribution of cards to player 1
cardDistributor(play2,exc, 2);//distribution of cards to player 2
cout<<"Welcome"<<endl;
game(play1,play2);

}

int game(vector<int>&play1,vector<int>& play2){
string Toptions1; string Toptions2;//strings to take actual card input
string Coptions1; string Coptions2;//strings to take called cards input
vector<int> pile;//pile vector
int Tnofc1; int Ttofc1; int Tnofc2; int Ttofc2; int Tnofc3; int Ttofc3; int Tnofc4; int Ttofc4;
//^^ints to keep track of cards entered
int totalp1;
int totalp2;
int Cnofc1=0; int Ctofc1=0;
int Cnofc2=0; int Ctofc2=0;
vector<bool> passv={false,false};
int noofturns=2;
int c=1;

while(c==1){
if(noofturns%2==0){
InHandPrint(play1);
totalp1=0;
noofturns++;
getline(cin,Coptions1);
cout<<endl<<Coptions1;

task1(Coptions1, Cnofc1, Ctofc1);


getline(cin,Toptions1);

task1(Toptions1,Tnofc1,Ttofc1);

getline(cin,Toptions1);


task1(Toptions1,Tnofc2,Ttofc2);

getline(cin,Toptions1);
task1(Toptions1,Tnofc3,Ttofc3);

getline(cin,Toptions1);


task1(Toptions1,Tnofc4,Ttofc4);
task2(Cnofc1, Ctofc1);


totalp1=totalp1+Tnofc1+Tnofc2+Tnofc3+Tnofc4;
task3(Tnofc1,Ttofc1,Tnofc2,Ttofc2,Tnofc3,Ttofc3,Tnofc4,Ttofc4, play1, play2, pile, passv, noofturns,totalp2,Ctofc2);
cin.get();}
else if(noofturns%2==1){
InHandPrint(play2);
totalp2=0;
noofturns++;
getline(cin,Coptions2);
task1(Coptions2, Cnofc2, Ctofc2);

cout<<"done"<<endl;

getline(cin,Toptions2);
task1(Toptions2,Tnofc1,Ttofc1);
cout<<"done"<<endl;
getline(cin,Toptions2);
task1(Toptions2,Tnofc2,Ttofc2);

cout<<"done"<<endl;
getline(cin,Toptions2);
task1(Toptions2,Tnofc3,Ttofc3);

cout<<"done"<<endl;
getline(cin,Toptions2);

task1(Toptions2,Tnofc4,Ttofc4);
cout<<Cnofc2<<Ctofc2<<endl;
task2(Cnofc2, Ctofc2);

cout<<"done"<<endl;
totalp2=totalp2+Tnofc1+Tnofc2+Tnofc3+Tnofc4;


task3(Tnofc1,Ttofc1,Tnofc2,Ttofc2,Tnofc3,Ttofc3,Tnofc4,Ttofc4, play2, play1, pile, passv, noofturns, totalp1, Ctofc1);
cin.get();
}
}}
void bluffcheck(vector<int>&play1,vector<int>&play2,vector<int>pile, int nofturns, int totp, int ctofc){
vector<int>last4;
bool blufft=false;
for(int t=0;t<totp;t++){
last4.push_back(pile[pile.size()-(t+1)]);

}
sort(last4.begin(),last4.end());
int a=last4[0];
for(int i=0;i<totp;i++){

if((last4[i]-ctofc)%13==0){

blufft=false;
}else{blufft=true;break;}
}
if(blufft==true){

cout<<"bluff right"<<endl;
nofturns--;
int pilesize=pile.size();
for(int i=0;i<pilesize;i++){

play2.push_back(pile[i]);

}
pile.clear();

}else if(blufft==false){

cout<<"bluff wrong"<<endl;
for(int i=0;i<pile.size();i++){

play1.push_back(pile[i]);
}
pile.clear();
}

}

void pass(vector<int>pile,vector<bool>pval,int n){
pval[n-1]=true;
if(pval[0]&&pval[1]){
pile.clear();

}
}

void task3(int nfc1, int tfc1, int nfc2, int tfc2, int nfc3, int tfc3, int nfc4,int tfc4, vector<int>&play1,vector<int>&play2, vector<int>&pile,vector<bool>&pval, int nofturns, int totp, int ctofc){
int totalnfc=nfc1+nfc2+nfc3+nfc4;
int arrtfc[4]={tfc1,tfc2,tfc3,tfc4};
if(nfc1==14&&tfc1==15){
int n;
if(play1[0]==1){
n=1;
}else if(play1[0]==2){
n=2;
}
pass(pile,pval,n);
}else if(nfc1==16&&tfc1==17){
bluffcheck(play1,play2,pile,nofturns,totp,ctofc );

}
else{

for(int q=1;q<=totalnfc;q++){
for(int a=1;a<=play1.size();a++){
for(int i=arrtfc[q];i<=(39+arrtfc[q]);i=i+13){
if(play1[a]==numbers[i]){
pile.push_back(numbers[i]);
int temp=play1[play1.size()-1];

play1[a]=temp;
play1.pop_back();
}}
}}



}

}
void task2(int nnfc, int ttfc){
if(nnfc==14&&ttfc==15){
cout<<"turn Passed"<<endl;
}else if(nnfc==16&&ttfc==17){
cout<<"bluff Called"<<endl;
}else{ cout<<endl<<nnfc<<endl;
switch (nnfc){

case 1:
cout<<"one";
break;
case 2:
cout<<"two";
break;
case 3:
cout<<"three";
break;
case 4:
cout<<"four";
break;
default:
break;
}
switch(ttfc){

case 1:
cout<<" Ace(s)"<<endl;
break;
case 2:
cout<<" Two(s)"<<endl;
break;
case 3:
cout<<" Three(s)"<<endl;
break;
case 4:
cout<<" Four(s)"<<endl;
break;
case 5:
cout<<" Five(s)"<<endl;
break;
case 6:
cout<<" Six(es)"<<endl;
break;
case 7:
cout<<" Seven(s)"<<endl;
break;
case 8:
cout<<" Eight(s)"<<endl;
break;
case 9:
cout<<" Nine(s)"<<endl;
break;
case 10:
cout<<" Ten(s)"<<endl;
break;
case 11:
cout<<" Jack(s)"<<endl;
break;
case 12:
cout<<" Queen(s)"<<endl;
break;
case 13:
cout<<" King(s)"<<endl;
break;
default:
break;
}


}
}

void task1(string opt, int& nfc, int&tfc){

if(opt.size()==1){
switch (opt[0]){
case '0':
nfc=0;
tfc=0;
break;
case 'p':
nfc=14;
tfc=15;
break;
case 'b':
nfc=16;
tfc=17;
break;
default:
break;
}
}
else if(opt.size()>1){ cout<<"started"<<endl;


switch (opt[0]){

case '1':
nfc=1;
break;
case '2':
nfc=2;
break;
case '3':
nfc=3;
cout<<nfc<<endl;
break;
case '4':
nfc=4;
break;
default:
break;
}

switch (opt[2]){
case '1':
tfc=1;
break;
case '2':
tfc=2;
break;
case '3':
tfc=3;
break;
case '4':
tfc=4;
break;
case '5':
tfc=5;
break;
case '6':
tfc=6;
break;
case '7':
tfc=7;
break;
case '8':
tfc=8;
break;
case '9':
tfc=9;
break;
}

if(opt.size()==4){
switch(opt[3]){
case '0':
tfc=10;
case '1':
tfc=11;
case '2':
tfc=12;
case '3':
tfc=13;
}

}
cout<<"ended"<<endl;

}}
void InHandPrint( vector<int>play){
cout<<flush;
system("CLS");
cout<<play[0]<<endl;
cout<<"{ ";
for(int i=1;i<=26;i++){
cout<<names[play[i]]<<", ";
if(i%3==0){
cout<<endl;
}}
cout<<" }"<<flush;
}
void cardDistributor(vector<int>&play,vector<int>&excl, int n){
for(int a=0;a<=26;a++){
if(a<26){
play.push_back(shuffler(excl));}
if(a==26){

play.push_back(n);
int temp;
temp=play[0];
play[0]=play[26];
play[26]=temp;
}
}}
int shuffler(vector<int> &ex){
int n=0;
n= rand()%(52-1 + 1) + 1;
bool b=false;
if(ex.size()==0){

ex.push_back(n);
return n;
}else if(ex.size()>=1){
for(int i=0;i<ex.size();i++){

if(ex[i]!=n){

b=true;

}else if (ex[i]==n){

b=false;
break;

}


}
if(b==true){

ex.push_back(n);
return n;
}else if (b==false){

return shuffler(ex);
}

}

}






c++ performance playing-cards






share|improve this question







New contributor




rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 15 hours ago









rowaim fazal

1




1




New contributor




rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






rowaim fazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by tinstaafl, πάντα ῥεῖ, Incomputable, Edward, Mathias Ettinger 14 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – tinstaafl, πάντα ῥεῖ, Incomputable, Edward, Mathias Ettinger

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by tinstaafl, πάντα ῥεῖ, Incomputable, Edward, Mathias Ettinger 14 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – tinstaafl, πάντα ῥεῖ, Incomputable, Edward, Mathias Ettinger

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Code not working as intended is not ready for review and off topic on Code Review. Looks on-topic in SO - heed item 1 spelling out how to get debugging support on SO.
    – greybeard
    14 hours ago










  • Even on SO that's way to big. You need to do some work in trying to narrow down the problem. Also if you want people to help you should fix the formatting. There is nothing more annoying than trying to read badly formatted code. To make it easy to copy and paste remove all tabs from your source (your IDE should be able to do it) and then get your IDE to do standard formatting. Then copy and paste that. the 'button' marked '{}' in the edit window will then add the indentation required for you.
    – Martin York
    7 hours ago














  • 2




    Code not working as intended is not ready for review and off topic on Code Review. Looks on-topic in SO - heed item 1 spelling out how to get debugging support on SO.
    – greybeard
    14 hours ago










  • Even on SO that's way to big. You need to do some work in trying to narrow down the problem. Also if you want people to help you should fix the formatting. There is nothing more annoying than trying to read badly formatted code. To make it easy to copy and paste remove all tabs from your source (your IDE should be able to do it) and then get your IDE to do standard formatting. Then copy and paste that. the 'button' marked '{}' in the edit window will then add the indentation required for you.
    – Martin York
    7 hours ago








2




2




Code not working as intended is not ready for review and off topic on Code Review. Looks on-topic in SO - heed item 1 spelling out how to get debugging support on SO.
– greybeard
14 hours ago




Code not working as intended is not ready for review and off topic on Code Review. Looks on-topic in SO - heed item 1 spelling out how to get debugging support on SO.
– greybeard
14 hours ago












Even on SO that's way to big. You need to do some work in trying to narrow down the problem. Also if you want people to help you should fix the formatting. There is nothing more annoying than trying to read badly formatted code. To make it easy to copy and paste remove all tabs from your source (your IDE should be able to do it) and then get your IDE to do standard formatting. Then copy and paste that. the 'button' marked '{}' in the edit window will then add the indentation required for you.
– Martin York
7 hours ago




Even on SO that's way to big. You need to do some work in trying to narrow down the problem. Also if you want people to help you should fix the formatting. There is nothing more annoying than trying to read badly formatted code. To make it easy to copy and paste remove all tabs from your source (your IDE should be able to do it) and then get your IDE to do standard formatting. Then copy and paste that. the 'button' marked '{}' in the edit window will then add the indentation required for you.
– Martin York
7 hours ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei