i have tried to write a code, but i have a problem with the play() module where the message "one Row Completed" is not being displayed. Please help me with this:icon_confused:

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class bingo
{
  public:int a[5][5];
	 void input();
	 void check();
	 void play();
	 void comp();
};

void bingo::input()//input a 5*5 matrix
{
   int i,j,num;
   cout<<"\n Enter numbers 1-25\n";
   for(i=0;i<5;i++)
   {
     for(j=0;j<5;j++)
     {
       cin>>a[i][j];
     }
     endl;
   }
}

void bingo::check()//no number 1-25 must be repeated
{       int error=0;
    for(int i=0;i<5;i++)
    {
     for(int j=0;j<5;j++)
     {
       int num=a[i][j];
       if(num==a[i][j+1])
       {
	 error=1;
       }
     }
    }
    if(error>0)
    {
      cout<<"\n Number repeated\n";
      cout<<"PLEASE START OVER\n";
      cout<<"\a";
      getch();
      exit(0);
    }
}

void bingo::play()
{
  cout<<"\n START GAME\n";
  for(int cal=1;cal<=25;cal++)//print input
  {
   for(int i=0;i<5;i++)
    {
     for(int j=0;j<5;j++)
     {
      cout<<a[i][j]<<" ";
     }
    cout<<"\n"<<"\n";
  }
    cout<<"\n Enter the number to be striked\n";
    int num,j,k=0,diag=0;
    cin>>num;
    for(i=0;i<5;i++)//place 0 in place of num
    {
      for(j=0;j<5;j++)
      {
	if(num==a[i][j])
	{
	  a[i][j]=0;
	  if((a[k][k]==0)&&(diag!=5))//check for diagnol elements
	  {
	     diag++;
	     k++;
	     if(diag==5)//if all the 5 elents are 0
	      cout<<"\n Row completed\n";
	  }
	}
      }
    }
  }
}
void main()
{
   clrscr();
   bingo b;
   b.input();
   b.check();
   b.play();
}

Edited 5 Years Ago by Narue: Added code tags

Think about what you need to do. At lines 66-72 you look for a square matching the number, and if you find it, you set it to zero. That much is good. You might want to include code to print an error to the user if he entered a number that isn't on the board.

The check for whether the diagonal is completed can be done separately, if a square was successfully cleared. In fact, you only need to check the top-left to bottom-right diagonal if i == j for the number found and cleared. You will also want to check if row i is clear, if column j is clear, and (I leave the logic to you) if the top-right to bottom-left diagonal is clear.

In addition, your check for whether any number is repeated isn't complete, it only checks whether two adjacent numbers are the same, and has an indexing error at the right-hand edge of each row.

i am trying to check if all the diagonal elements are 0 and parallely trying to increment the value of diag for each diagonal element equal to 0.:)

Move the declaration of int num,j,k=0,diag=0; out of the loop 'for(int cal=1;cal<=25;cal++)//print input'

Because they are again and again getting reinitialized.
I think this will solve your problem.

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