1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#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();
}
|