I can not figure out why this code is compiling but crashing. Any help would be awesome! I am trying to make a full deck of cards and put each card into a struct so I can use any of the info I need.
int response;
cout << "Pick a Card any card 0 - 52\n";
cin>>response;
cout<<"card value is: "<<card[response].vaule<<"\n";
cout<<"cards face is: "<<card[response].face<<"\n";
cout<<"cards suite is: "<<card[response].suite<<"\n";
}
it will crash because x and z are incremented before they are used. Put the increment at the end of the loop.
By the way: You will never get out of the while(go !="Stop") loop because when you enter anything but 0 - 52 it will crash and response is int not string
string go = "go";
while(go !="Stop")
{
int response;
cout << "Pick a Card any card 0 - 52\n";
cin>>response;
cout<<"card value is: "<<card[response].vaule<<"\n";
cout<<"cards face is: "<<card[response].face<<"\n";
cout<<"cards suite is: "<<card[response].suite<<"\n";
}
return 0;
}
Above code will complile
in first function you are starting with 0
and in others you are starting with 1
program in crashing when it reaches j=25.
And two extra lines in while loop will helps to control the flow of program
while(go !="Stop")
{
int response;
cout << "Pick a Card any card 0 - 52\n";
cin>>response;
cout<<"card value is: "<<card[response].vaule<<"\n";
cout<<"cards face is: "<<card[response].face<<"\n";
cout<<"cards suite is: "<<card[response].suite<<"\n";
cout<<"Enter go to Select next card and Stop to end"<<endl;
cin>>go;
}
string go = "go";
while(go !="Stop")
{
int response;
cout << "Pick a Card any card 0 - 52\n";
cin>>response;
cout<<"card value is: "<<card[response].vaule<<"\n";
cout<<"cards face is: "<<card[response].face<<"\n";
cout<<"cards suite is: "<<card[response].suite<<"\n";
}
return 0;
}
Above code will complile
in first function you are starting with 0
and in others you are starting with 1
program in crashing when it reaches j=25.
Thanks so much for your help on this moving the counter variables to the end of the for loop did the trick. I am hoping that this can become a set-up function that is general enough to be used in all types of card games.