0

can you help me to fix my program? how can i non-repeat the numbers i don't know the code..and how can i generate a numbers for bingo?...i need to generate until i win..

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

const int ROWS = 5;
const int COLUMNS = 5;
     
int main()
{


cout << "  B 	  I 	  N 	  G 	  O\n\n";
srand(time(0));
int   card[ROWS][COLUMNS] = {{rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31, rand() % 15 + 46, rand() % 15 + 61},					
                            {rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31, rand() % 15 + 46, rand() % 15 + 61},
                            {rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31 ,rand() % 15 + 46, rand() % 15 + 61},						
                            {rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31, rand() % 15 + 46, rand() % 15 + 61},		
                            {rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31, rand() % 15 + 46, rand() % 15 + 61}};
	

for (int i = 0; i < ROWS; i++)
	{
        for (int j = 0; j < COLUMNS; j++)
			{
			cout << card[i][j];
			cout << "\t|"; 		
        }
		cout <<"\n";
	}
    system("pause");
    	}

Edited by demigodz24: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by daviddoria
0
srand(time(0));
int   card[ROWS][COLUMNS] = {{rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31, rand() % 15 + 46, rand() % 15 + 61},					
                            {rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31, rand() % 15 + 46, rand() % 15 + 61},
                            {rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31 ,rand() % 15 + 46, rand() % 15 + 61},						
                            {rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31, rand() % 15 + 46, rand() % 15 + 61},		
                            {rand() % 15 + 1, rand() % 15 + 16, rand() % 15 + 31, rand() % 15 + 46, rand() % 15 + 61}};

I'm assuming your problem is here. You could use for loops to iterate through the 2 d array and set each value independently, instead of setting the whole array at once. Then to make sure you haven't duplicated any you could check each value generated with the previously generated values. Take a look at subscripting 2 dimensional arrays here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.