Uhm, so hello! We have this project in our CS course that states that we have to generate our own Bingo Game program, we can use help or we can let a person/people work on it as long as we can understand it. But I chose the latter part of doing it with my partner, but by just asking for help. So here it is, I have this code for generating a card in a bingo game. It has a range, e.g. (B=1-15, I=16=30.....) until O that's until the number 75 only. It's already fixed, the only problem is that when I generate a number in the column B, and the other columns as well, the numbers are repeating. I've spent a day to 3 thinking and experimenting on my program, but still it repeats the number on a column! Uhh, can you guys help me with these? I'm a beginner, thank you! I also tried putting it in variables, and validating it one-by-one, but still it doesn't work. :(
`

#include<iostream>
#include<ctime>
#include<conio.h>
using namespace std;
void main()
{

    int num[5][5],row,col,a,b,c,d,e;
    int ask;

    srand(time(NULL));

    do{

        system("cls");
            cout<<"\n\n\t\t\t\t    BINGO GAME"<<endl;

        for(row=0;row<5;row++)
        for(col=0;col<5;col++)
            num[row][col]=rand()%100;

        cout<<"\n\n\tB\t\tI\t\tN\t\tG\t\tO"<<endl;
        cout<<"\n\n";

            for(row=0;row<5;row++)
            {                    
                for(col=0;col<5;col++)
                    {                   
                        if(col==0)
                            {
                                num[row][col]=rand()%15;

                                    if(row==0)
                                        a=num[row][col];
                                    else if(row==1)
                                        b=num[row][col];
                                    else if(row==2)
                                        c=num[row][col];
                                    else if(row==3)
                                        d=num[row][col];
                                    else if(row==4)
                                        e=num[row][col];                            
                            }

                        else if(col==1)
                        { 
                            num[row][col]=rand()%30;

                            do{
                                if(num[row][col]<=15)
                                {
                                    num[row][col]=num[row][col]+30;
                                }
                                else if(num[row][col]>=31)
                                {
                                    num[row][col]=num[row][col]-1;
                                }
                            }while((num[row][col]<=15)&&(num[row][col]>=31));

                        }
                        else if(col==2)
                        { num[row][col]=rand()%15;
                        do{
                            if(num[row][col]<=30)
                            {
                                num[row][col]=num[row][col]+45;
                            }
                            else if(num[row][col]>=46)
                            {
                                num[row][col]=num[row][col]-1;
                            }
                        }
                            while((num[row][col]<=30)&&(num[row][col]>=46));

                        }


                        else if(col==3)
                        { num[row][col]=rand()%15;
                            do{
                            if(num[row][col]<=45)
                            {
                                num[row][col]=num[row][col]+60;
                            }
                            else if(num[row][col]>=61)
                            {
                                num[row][col]=num[row][col]-1;
                            }
                        }
                            while((num[row][col]<=45)&&(num[row][col]>=61));
                        }
                        else if(col==4)
                        { num[row][col]=rand()%15;
                            do{
                            if(num[row][col]<=60)
                            {
                                num[row][col]=num[row][col]+60;
                            }
                            else if(num[row][col]>=91)
                            {
                                num[row][col]=num[row][col]-1;
                            }
                        }
                            while((num[row][col]<=60)&&(num[row][col]>=76));
                        }

                    if((row==2)&&(col==2))
                            cout<<"\tFREE\t";
                        else
                            cout<<"\t"<<num[row][col]<<"\t";

                    }
                    cout<<"\n";
            }

            {
                cout<<"\n\n\tIs this the card you want to use? [0 for no only.] : ";
                cin>>ask;
            }

    }
            while(ask!=0);

}

If I understand what you're saying, your problem is that when you generate random numbers, sometimes you generate a number you have already used?

So keep a record of all the numbers already used, and when you generate one, only use it if you haven't already used that number.

Comments
Yes! That's it. I tried validating it one by one as well, as I've stored the generated random number in a variable. D:

Have you tried making a list of all the numbers used so far, and then when you get the next number, looking at the list to see if you've already used that one?

Comments
This article has been dead for over six months. Start a new discussion instead.