Hi everyone:)
I am still not able to complete this:(

#include<iostream.h>
#include<conio.h>

class bingo
{
public:int a[5][5];
void input();
void play();
};

void bingo::input()//input a 5*5 matrix
{
int i,j,num,check=0,l,m;
cout<<"\n Enter numbers 1-25\n";
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
cin>>a[i][j];
num=a[i][j];
for(l=0;l<5;l++)//check if number has repeated
{
for(m=0;m<5;m++)
{
if(a[l][m]==num)
check++;
if(check==2)
{
cout<<"\n Number repeated\nStart again!\n";
getch();
exit(0);
}
}
}
}
}
}
void bingo::play()
{
int i,j,cal;
cout<<"\n START GAME\n";
for(cal=1;cal<=25;cal++)//print input
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
cout<<a[i][j]<<" ";
}
cout<<"\n"<<"\n";
}
cout<<"\n Enter the number to be striked\n";
int ele,diag1=0,diag2=0,row1=0,row2=0,row3=0,row4=0,row5=0;
int col1=0,col2=0,col3=0,col4=0,col5=0,game=01;
cin>>ele;
for(i=0;i<5;i++)//place 0 in place of ele
{
for(j=0;j<5;j++)
{
if(ele==a[i][j])
{
a[i][j]=0;
if(a[i][j]==0 && i==j)//principle diagonal
{
diag1++;
if(diag1==5)
cout<<"\n Row completed\n";
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
switch(i) //checking rows
{
case 0: if(a[i][j]==0)
{
row1++;
if(row1==5)
cout<<"\n Row completed\n";
j++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
case 1: if(a[i][j]==0)
{
row2++;
if(row2==5)
cout<<"\n Row completed\n";
j++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
case 2:if(a[i][j]==0)
{
row3++;
if(row3==5)
cout<<"\n Row completed\n";
j++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
case 3:if(a[i][j]==0)
{
row4++;
if(row4==5)
cout<<"\n Row completed\n";
j++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
case 4:if(a[i][j]==0)
{
row5++;
if(row5==5)
cout<<"\n Row completed\n";
j++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
default: break;
}
switch(j)//checking for columns
{
case 0:if(a[i][j]==0)
{
col1++;
if(col1==5)
cout<<"\n Row completed\n";
i++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
case 1:if(a[i][j]==0)
{
col2++;
if(col2==5)
cout<<"\n Row completed\n";
i++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
case 2:if(a[i][j]==0)
{
col3++;
if(col3==5)
cout<<"\n Row completed\n";
i++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
case 3:if(a[i][j]==0)
{
col4++;
if(col4==5)
cout<<"\n Row completed\n";
i++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
case 4:if(a[i][j]==0)
{
col5++;
if(col5==5)
cout<<"\n Row completed\n";
i++;
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
break;
default: break;
}
}
}
}
i=0;j=4;//checking for the diagonal that's remaining
while(i!=4 && j!=0)
{
if(a[i][j]==0)
{
diag2++;
if(diag2==5)
cout<<"\n Row completed\n";
i++;j--;
}
game++;
if(game==5)
cout<<"\n Congo!!!!\nGame completed\n";
}
}
}
void main()
{
clrscr();
bingo b;
b.input();
b.play();
}

## All 4 Replies

void main()

Change "void main" to int main() .

Also, writing the program so that there is less coding would be beneficial, what happens when you try to run that thing?

Your code may be easier to follow if instead of trying to maintain the state of each row/column/diagonal each time the user strikes out a number, you just manually do the check. It will be marginally slower, but at only 25 squares to check, I don't think you'd notice! E.g.:

...
a[i][j] = 0;

// check if row is now clear
bool row_clear = true;
for (int jj = 0; jj < 5; jj++) {
if (a[i][jj] != 0) {
row_clear = false;
break;
}
}
if (row_clear) {
// do appropriate thing
}

// check column
// if i == j, check primary diagonal
// check other diagonal if appropriate

...

And for increased modularity, you might want to split that code into additional methods, e.g.:

bool bingo::is_row_clear(int i) {
...
}

and then call these new methods from your bingo::play() method.

Thanks a lot!:)

hello everyone!!
i would like to know the method or procedure used to match the input given by the user with the system's date and time and display the message at appropriate time.
its much of a to-do list kind of a program
i have written a code and its this;

#include <iostream.h>
#include <time.h>
#include<string.h>
#include<conio.h>

class todo
{
private: char m_dd[2],m_mm[2],m_yy[5],hh[2],mm[2],ss[2];
char s[],r[],msg[20];
public: void get_det();
void convert();
void result();
};

void todo::get_det()
{
cout<<"\n The format which has to be input is as shown--- Thu Jan 19 2012 21:27:56\n";
cout<<"\n Enter day of the week: ";
cin>>m_dd;
cout<<"\n Enter month: ";
cin>>m_mm;
cout<<"\n Enter date: ";
cin>>m_dd;
cout<<"\n Enter time in 24hr format\n Hour: ";cin>>hh;cout<<"\n Minutes: ";cin>>mm;cout<<" \n Seconds: ";
cin>>ss;
cout<<"\n Enter year: ";
cin>>"2012";
cout<<"\n Enter note: ";
cin>>msg;
}

void todo:: convert()
{
strcat(s,m_dd);
strcpy(s," ");
strcpy(s,m_mm);
strcpy(s," ");
strcpy(s,m_dd);
strcpy(s," ");
strcat(s,hh);
strcat(s,":");
strcat(s,mm);
strcat(s,":");
strcat(s,ss);
strcat(s," ");
strcat(s,m_yy);
}

void todo::result()
{
time_t tim;
time(&tim);
strcpy(r,ctime(&tim));
convert();
int com=(strcmp(s,r));
if(strlen(s)==strlen(r))
{
if((com < 0)||(com > 0)||(com == 0))
{
cout<<"\a";
cout<<msg;
}
}
else
return;
}

void main()
{
todo to;
clrscr();
to.get_det();
to.result();
getch();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.