I was creating a card game called broom, my while I need to make sure that all the cards in the hand are played, a card that is played automatically turns into 0 and theoretically, once all the cards in hand become 0 would come out of the while, this unfortunately does not happen, after playing the first card the program closes. I removed the part in which the card changes to 0 and the program does not close, consequently I think the problem is the while. (translated with google)
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int temp = 3;
int deck[40];
string seed[40];
int hand[3];
string seed_hand[3];
int bot_hand[3];
string seed_hand_bot[3];
int table[10];
string seed_table[10];
int choice;
string choice_seed;
void deck_generator();
void shuffle();
void distribution();
void hand_check();
int main()
{
deck_generator();
shuffle();
distribution();
cout << "----- WELLCOME -----" << endl << "this is just a beta of one hand of -scopa- have fun" << endl;
cout << endl;
cout << "Table:" << endl;
for (int i = 0; i < 4; i++) {
cout << table[i] <<" " << seed_table[i] << " ";
}
cout << endl << endl;
cout << "your hand:" << endl;
for (int i = 0; i < 3; i++) {
cout << hand[i] <<" " << seed_hand[i] << " ";
}
while (hand[0] != 0 && hand[1] != 0 && hand[2] != 0) {
cout << endl << "choose a card that you want to play typing the number and then the seed: " << endl;
cin >> choice;
cin >> choice_seed;
hand_check();
cout << endl;
cout << "table:" << endl;
for (int i = 0; i < 10; i++) {
cout << table[i] << " " << seed_table[i] << " ";
}
cout << endl << endl;
cout << "your hand:" << endl;
for (int i = 0; i < 3; i++) {
cout << hand[i] << " " << seed_hand[i] << " ";
}
}
return 0;
}
//genera un mazzo completamente ordinato con numeri e semi
void deck_generator() {
int j = 0;
for (int i = 0; i < 40; i++) {
j++;
deck[i] = j;
if (j == 10) {
j = 0;
}
if (i < 10) {
seed[i] = "golds";
}
else if (i >= 10 && i < 20) {
seed[i] = "sticks";
}
else if (i >= 20 && i < 30) {
seed[i] = "swords";
}
else if (i >= 30 && i < 40) {
seed[i] = "cups";
}
}
}
// tramite un numero estratto casualmente mischia le carte
void shuffle() {
int number;
int random;
int exchange;
string swap;
srand(time(NULL));
for (int i = 0; i < 40; i++) {
number = rand() % 40;
random = rand() % 40;//metto due numeri a confronto e dopo di che faccio delle sostituzioni sia dei semi sia dei numeri
if (number != random) {
exchange = deck[number + 1];
deck[number + 1] = deck[random];
deck[random] = exchange;
swap = seed[number + 1];
seed[number + 1] = seed[random];
seed[random] = swap;
}
}
}
void distribution() {
int m = 4;
int n = 8;
//qui vengono distribuite le prime carte presenti nell'array al giocatore
for (int i = 0; i < 3; i++) {
hand[i] = deck[i];
seed_hand[i] = seed[i];
}
//qui metteremo le carte in campo
for (int i = 0; i < 4; i++) {
table[i] = deck[m];
seed_table[i] = seed[m];
m++;
}
//qui daremo le carte al bot
for (int i = 0; i < 3; i++) {
bot_hand[i] = deck[n];
seed_hand_bot[i] = seed[n];
n++;
}
}
void hand_check() {
temp++;
for (int i = 0; i < 3; i++) {
if (choice == hand[i] && choice_seed==seed_hand[i]){
table[temp] = choice;
seed_table[temp] = choice_seed;
hand[i] = 0;
seed_hand[i] = " ";
}
}
}