I'm trying to display different approach of random numbers in multiple 2D array, but the result that i got is the same. All my 2D arrays had the same results.
#include <ctime>
#include <iostream>
#include <string>
usingnamespace std;
struct Board
{
string Name;
constint array_size = 5; // 19 is maximum to keep all numbers in straight columns
int middle = array_size / 2; // Remove this if not making Bingo board
int max_num = array_size*array_size;
int numbers[25]; // size is max_num - Keep track of all numbers created
int value[5][5];
};
int main()
{
bool ok;
int n, z, i, j, x, y;
int Playing;
srand((unsigned)time(0));
Board Player[10]; // Maximum playing
cout << "How many players ? [1 to 10]" << endl;
do
{
cin >> Playing;
if (Playing < 1)
cout << "Seems no one is playing. Let's try this again." << endl;
if (Playing > 10)
cout << "We only have 10 openings." << endl;
} while (Playing < 1 || Playing > 10);
for (int x = 0; x < Playing; x++)
{
cout << "Enter player #" << x + 1 << "'s first name.." << endl;
cin >> Player[x].Name;
}
for (y = 0; y < Playing; y++)
{
z = 0;
cout << "Working on player " << Player[y].Name << endl;
for (i = 0; i < Player[y].array_size; i++)
{
for (j = 0; j < Player[y].array_size; j++)
{
do
{
ok = true;
n = (1 + rand() % 15) + (j * 15); // For a 5x5 Bingo card
//n = 1+rand()% Player[y].max_num;//else 1 to maximum number
for (x = 0; x < z; x++)
{
if (n == Player[y].numbers[x])
{
ok = false;
}
}
} while (!ok);
Player[y].numbers[z] = n;
Player[y].value[i][j] = n;
z++;
}
}
}
for (y = 0; y < Playing; y++)
{
cout << "Player " << Player[y].Name << "'s board. " << endl;
for (i = 0; i < Player[y].array_size; i++)
{
for (j = 0; j < Player[y].array_size; j++)
{
if (i == Player[y].middle && j == Player[y].middle) // Remove this if not making Bingo board
{
cout << " Fr "; // Don't need free space if NOT bingo
}
else
{
if (Player[y].value[i][j] < 10) // Just to make numbers into even columns
cout << " ";
if (Player[y].value[i][j] < 100) // Just to make numbers into even columns
cout << " ";
cout << Player[y].value[i][j] << " "; // Print numbers
}
}
cout << endl;
}
cout << endl << endl;
}
return 0;
}
@whitenite1
Thankyou so much for you help. But do you know how to determine the winner as well? Because i just know how to determine the winner if it has the fixed size board. How if the user want to enter the size by itself (let say between 3 to 5)? Of course i cannot use the usual method to determine the winner.
I have no idea how to determine a winner, as I have NO idea on how the game is played, nor what the numbers in the arrays, mean. If you could supply the rules, I should be able to figure out how a player may win. Letting the user determine the size is relatively easy.
Change the struct to:
1 2 3 4 5 6 7 8 9
struct Board
{
string Name;
constint array_size = 5; // Change to largest amount of array size
//int middle = array_size / 2; // Removed. This isn't a Bingo board
int max_num = array_size*array_size;
int numbers[25]; // size is value of array_size*array_size
int value[5][5];// Change the tw0 5's to the value of array_size
};
There's a bit of code changing later also, but we'll get to that after I find out the rules.. ;)