Bingo Game

Making a bingo game

Page 1 of 1

11 Replies - 28885 Views - Last Post: 06 March 2010 - 04:42 PM Rate Topic: -----

#1 noobprogram   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 26-January 10

Bingo Game

Posted 02 March 2010 - 06:59 AM

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

main(void)
{

 int bingo[5][5];
 int row;
 int col;
 int num=15;

 randomize();
 clrscr();

 for(row=0;row<5;row++)
 {

  for(col=0;col<5;col++)

   {

    bingo[row][col]=rand()%num+1;

   }

   printf("\n");

 }

 for(row=0;row<5;row++)
 {

  for(col=0;col<5;col++)

   {

    printf("%d\t", bingo[row][col]);

   }

   printf("\n");

 }

 getch();

}


The only problem in this code that every column like (e.g.) B would have a random numbers from 1-15 and I:16-30 N:31-45 G:46-60 and O:61-75.

Is This A Good Question/Topic? 0
  • +

Replies To: Bingo Game

#2 Martyn.Rae   User is offline

  • The programming dinosaur
  • member icon

Reputation: 553
  • View blog
  • Posts: 1,433
  • Joined: 22-August 09

Re: Bingo Game

Posted 02 March 2010 - 07:22 AM

So what is your problem exactly?
Was This Post Helpful? 0
  • +
  • -

#3 Guest_taylorc8*


Reputation:

Re: Bingo Game

Posted 02 March 2010 - 07:26 AM

What compiler are you using?

please look up the srand() and rand() functions, the modulus % operator can help you with getting random numbers between a certain range, because it returns the modulus after division, meaning less than whatever it is you're dividing by. srand() should be called once for the life of your program, it is commonly seeded with the time.

srand(time(0));

int random=(rand() % 25) + 1; // add one to eliminate zero remainder


Was This Post Helpful? 0

#4 Ferencn   User is offline

  • D.I.C Regular
  • member icon

Reputation: 71
  • View blog
  • Posts: 322
  • Joined: 01-February 10

Re: Bingo Game

Posted 02 March 2010 - 07:33 AM

Try this:
Always generate a number in the range 1-15.
Then add the correct offset (0 for column 1, 15 for column 2, 30 for column 3 etc. hint: looks a lot like 15*col) to that number, before storing it in the destination [row][col].
I think you also have to check that there are no duplications in a column.

Edit: sloppy interpunction

This post has been edited by Ferencn: 02 March 2010 - 07:36 AM

Was This Post Helpful? 2
  • +
  • -

#5 khellie_15   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 02-March 10

Re: Bingo Game

Posted 02 March 2010 - 08:09 AM

View Postnoobprogram, on 02 March 2010 - 05:59 AM, said:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

main(void)
{

 int bingo[5][5];
 int row;
 int col;
 int num=15;

 randomize();
 clrscr();

 for(row=0;row<5;row++)
 {

  for(col=0;col<5;col++)

   {

    bingo[row][col]=rand()%num+1;

   }

   printf("\n");

 }

 for(row=0;row<5;row++)
 {

  for(col=0;col<5;col++)

   {

    printf("%d\t", bingo[row][col]);

   }

   printf("\n");

 }

 getch();

}


The only problem in this code that every column like (e.g.) B would have a random numbers from 1-15 and I:16-30 N:31-45 G:46-60 and O:61-75.




there are repeating numbers?

This post has been edited by khellie_15: 02 March 2010 - 08:15 AM

Was This Post Helpful? 1
  • +
  • -

#6 Ferencn   User is offline

  • D.I.C Regular
  • member icon

Reputation: 71
  • View blog
  • Posts: 322
  • Joined: 01-February 10

Re: Bingo Game

Posted 02 March 2010 - 10:08 AM

There can be!
Like throwing a die: every time you do so, each side has an even chance of ending up! The same is true for a random number generator...
Was This Post Helpful? 0
  • +
  • -

#7 khellie_15   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 02-March 10

Re: Bingo Game

Posted 02 March 2010 - 07:35 PM

View PostFerencn, on 02 March 2010 - 09:08 AM, said:

There can be!
Like throwing a die: every time you do so, each side has an even chance of ending up! The same is true for a random number generator...




so how can i eliminate this repeating numbers. Bingo game must not have repeating numbers.
Was This Post Helpful? 0
  • +
  • -

#8 noobprogram   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 26-January 10

Re: Bingo Game

Posted 02 March 2010 - 07:49 PM

Updated:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

main(void)
{

 int bingo[5][5];
 int all[25]={0};
 int row;
 int col;
 int num=0;
 int limit=1;

 randomize();
 clrscr();

 for(row=0;row<5;row++)
 {

  num+=15;

  for(col=0;col<5;col++)
  {

    for(;;)/>
    {

      bingo[row][col]=rand()%num+1;

       if(all[bingo[row][col]]==0)
       {

	all[bingo[row][col]]++;
	break;

       }

    }

  }

  limit+=15;

 }

 for(row=0;row<5;row++)
 {

  for(col=0;col<5;col++)

   {

    if(row==2 && col==2)
    {

     printf("FREE\t");

    }

    else

     printf("%d\t", bingo[col][row]);

   }

   printf("\n\n");

 }

 getch();

}


It is not repeating any number now, the only problem is that I have to print like a bingo card, column B must have 1-15 numbers and I:16-30 etc.

here's a sample output:
Posted Image

This post has been edited by noobprogram: 02 March 2010 - 08:38 PM

Was This Post Helpful? 0
  • +
  • -

#9 jcmaster2   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 183
  • Joined: 27-April 09

Re: Bingo Game

Posted 02 March 2010 - 09:41 PM

//first generate a number between 1-15

value = rand() % 15 + 1;

//offset it by 15 for each column

bingoCard[i][j] = value + (col * 15);



make your appropriate changes...
Was This Post Helpful? 0
  • +
  • -

#10 noobprogram   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 26-January 10

Re: Bingo Game

Posted 03 March 2010 - 06:52 AM

View Postjcmaster2, on 03 March 2010 - 11:41 AM, said:

//first generate a number between 1-15

value = rand() % 15 + 1;

//offset it by 15 for each column

bingoCard[i][j] = value + (col * 15);



make your appropriate changes...


If do that it will exceed the limit (e.g.) the computer randomized a number and it is 1, then 1+(1*15) the value will be 16 that will exceed the boundary between 0-15 for the 1st col which is B.

This post has been edited by noobprogram: 03 March 2010 - 06:53 AM

Was This Post Helpful? 0
  • +
  • -

#11 noobprogram   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 26-January 10

Re: Bingo Game

Posted 06 March 2010 - 11:01 AM

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

main(void)
{

 int bingo[5][5];
 int row;
 int row1;
 int col;
 int num=15;
 int num1=0;
 int value=0;

 randomize();
 clrscr();

 for(row=0;row<5;row++)
 {

  for(col=0;col<5;col++)
  {

   for(;;)/>
   {

     value=rand()%num+1;

     bingo[row][col]=value+num1;

   }

  }

  num1+=15;

 }

 for(row=0;row<5;row++)
 {

  for(row1=1;row<row1;row1++)
  {

   do
   {

    value=rand()%num+1;

    bingo[row]=value+num1;


   }while(bingo[row]==bingo[row1]);

  }

 }

 printf("B\tI\tN\tG\tO\n\n");

 for(row=0;row<5;row++)
 {

  for(col=0;col<5;col++)

   {

    if(row==2 && col==2)
    {

     printf("FREE\t");

    }

    else

     printf("%d\t", bingo[col][row]);

   }

   printf("\n\n");

 }

 getch();

}


Well I have done it! the only problem is that it repeats some numbers from the same column, I wanted to know how to compare a 2D array or simply eliminate/change the repeated numbers.
Was This Post Helpful? 0
  • +
  • -

#12 jcmaster2   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 183
  • Joined: 27-April 09

Re: Bingo Game

Posted 06 March 2010 - 04:42 PM

Well OK..then this should work...I did a bingo card generator once long ago...

Modify it as need...It check for repeats...

void FillCard(int BCard[][5])
{
	int row, col, value, i;
	bool check[76];    //need values 1-75

	//First fill check array with falses
	for(i = 0; i < 76; ++i)  
		check[i] = false;
	
	bool again;  //flag to get another value

	for(col = 0; col < 5; ++ col) //work on each col
	{
		//now go down each row
		for(row = 0; row < 5; ++ row)
		{
			//check if we're at [2][2] FREE
			if(row == 2 && col == 2)
			{
				BCard[row][col] = 100; //indicate FREE
				continue;	//jump to next loop iteration
			}

			again = true;
			do
			{
				//first generate a number between 1-15
				value = rand()%15 + 1;

				//offset it by 15 for each column
				value = value + (col*15);
	
				//now check if we've gotten that number before
				//if we have, do this again	
				if(check[value] == false) 
				{
					BCard[row][col] = value;
					check[value] = true;
					again = false;
				}
			}while(again == true);
		}
	}
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1