SOLVED Help with C++ project

Hello, for school we are doing a mancala project in c++. I’m currently making a function that is supposed to pick up the beads from the bin selected, and then place one in the next bins clockwise until the “hand” is empty. If the last bead is placed a bin that already has beads in it, the hand picks the beads up from that bin and repeats. If the last bead is put in their endbin, the player gets to choose (from their own side of the board) what bin they want to pick from. If the last bead is placed in a bin that had zero beads in it, the turn ends. The program is not supposed to place beads in the opposing players bin.

I’m going to keep working finding the errors, there’s just been times where my problem is something obvious I keep overlooking, but I spend hours trying to fix it when it would’ve been solved in 5 minutes if I just asked for another set of eyes to look at it.

I really appreciate the help, even if you don’t know exactly what the problem is, knowing what might be the problem is still a big help.

A couple problems I am having are:

  • the program asks the user which bin they want twice. The first time nothing happens, but then the second time the user chooses a bin it begins the process.

  • the program isn’t skipping the opposing teams bin and I don’t know why. I have it coded so that it is supposed to move on to the next bin and do nothing to the opponents bin, but for some reason it is dropping in the opponents bin.

  • sometimes the program stops picking up beads when it isnt supposed to. For example, when I choose bin number five, the “hand” is supposed to pick up from bin 10 , however, instead it just asks the user what bin they want to choose instead of continuing.

It looks like the program isn’t entering the “player == etc” if statements.

Here’s a copy of my function :

int dropBeads( int player, int beadArray[MAX], int &bin )
{
	int opponentsBin;
	int endBin;
	player = 1;

	if (player == 1)
	{
		
		opponentsBin = beadArray[13];
		endBin = beadArray[6];
	}
	if (player == 2)
	{
		opponentsBin = beadArray[6];
		endBin = beadArray[13];
	}
	
	int winner = gameOverCheck( beadArray );
	do
	{
		getStartingBin( beadArray, bin );
		do
		{
			showBoard( beadArray );
			int hand = beadArray[bin];
			beadArray[bin] = 0;
			while (hand > 0)
			{
				bin++;
				if (bin == opponentsBin)
				{
					bin++;
				}
				if (bin > 13)
				{
					bin = 0;
				}
				beadArray[bin]++;
				hand--;
			}
		} while (beadArray[bin] != endBin && bin != endBin);
		
	} while (bin == endBin && winner == -1);
	
	return player;   // I haven't decided where to use this yet. I am going to add a 
//command to switch between player 1 and player 2, but right now
// I'm just trying to iron-out the basics
}
 

 // **Here's a copy of getStartingBin, a function that is called in this function :** 



/*****************************************************************************/
/* getStartingBin sets the correct bin range for both players' turns.        */
/* It asks the player to choose a bin and checks if the bin is within range, */
/*  and then it checks if the bin is empty or not. getStartingBin will keep  */
/*  asking the player to pick a bin until the bin chosen is within range and  */
/*   isn't empty.                                                             */
/****************************************************************************/

void getStartingBin( int beadArray[MAX], int &bin )
{
	int lowBin;
	int highBin;
	int player = 1;

	if (player == 1)
	{
		lowBin = 0;
		highBin = 5;
		cout << endl << "Player 1's turn to pick a bin." << endl;
	}
	else
	{
		lowBin = 7;
		highBin = 12;
		cout << endl << "Player 2's turn to pick a bin." << endl;
	}
	
	cout << "Enter bin:  " << endl;
	
	cin >> bin;
	while (bin < lowBin || bin > highBin || beadArray[bin] == 0)
	{
		cout << " You can only choose bins that: " << endl;
		cout << "	a) are on your side of the board  " << endl << "	b) have beads in them." << endl;
		cout << endl << "Enter a different bin: ";
		cin >> bin;

		
	}


}

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

oh ok! thank you I appreciate it