Thread: Bingo code not detecting BINGO.

  1. #1
    Registered User
    Join Date
    May 2018
    Posts
    4

    Bingo code not detecting BINGO.

    My bingo code works its just not detecting a bingo. Any help will be appreciated.
    Code:
    # include <iostream># include <string.h>
    # include <time.h>
    # include <cstdlib>
    # include <stdio.h>
    # include <termios.h>
    # include <unistd.h>
    # include <iomanip>
    using namespace std;
    ///////////////////////////////////////////////////////////////////////
    int getch()
    {
    	struct termios oldt, newt;
    	int ch;
    	tcgetattr(STDIN_FILENO, &oldt);
    	newt=oldt;
    	newt.c_lflag &= ~( ICANON | ECHO );
    	tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    	ch=getchar();
    	tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    	return ch;
    }
    ///////////////////////////////////////////////////////////////////////
    int MakeCard(int Board[5][15][2])
    {
    	srand(time(NULL));
    	int x,y,z,temp,random,swap;
    	for (y=0;y<15;y++)
    		for (x=0;x<5;x++)
    			Board[x][y][0]=x*15+y+1;
    	for (y=0;y<5;y++)
    	{
    		for (x=0;x<5;x++)
    		{
    			random=rand()%15;
    			temp=Board[x][random][0];
    			Board[x][random][0]=Board[x][y][0];
    			Board[x][y][0]=temp;
    		}
    	}
    	for (z=0;z<5;z++)
    		for (y=0;y<5;y++)
    			for (x=0;x<5;x++)
    				if (Board[x][y][0]>Board[x][y+1][0])
    				{
    					swap=Board[x][y][0];			// Sort dice
    					Board[x][y][0]=Board[x][y+1][0];
    					Board[x][y+1][0]=swap;
    				}
    	for (y=0;y<5;y++)
    		for (x=0;x<5;x++)
    			Board[x][y][1]=0;
    	return 0;	
    }
    ///////////////////////////////////////////////////////////////////////
    int Color(int Board[5][15][2],int posx,int posy)
    {
    	char normal[]={ 0x1b, '[', '0', ';', '3', '9', 'm', 0 }; //Declare Variables
    	char red[]={ 0x1b, '[', '0', ';', '3', '1', 'm', 0 };
    	char blue[]={ 0x1b, '[', '0', ';', '3', '4', 'm', 0 };
    	char green[]={ 0x1b, '[', '0', ';', '3', '2', 'm', 0 };
    	char purple[]={ 0x1b, '[', '0', ';', '3', '5', 'm', 0 };
    	char cyan[]={ 0x1b, '[', '1', ';', '3', '6', 'm', 0 };
    	char yellow[]={ 0x1b, '[', '0', ';', '3', '3', 'm', 0 };
    	int x,y;
    	cout<<blue<<"   B "<<green<<"   I "<<red<<"   N "<<purple<<"   G "<<yellow<<"   O "<<normal<<"\n";
    	cout<<cyan<<"╔════╦════╦════╦════╦════╗\n";
    	for (y=0;y<5;y++)
    	{
    		for (x=0;x<5;x++)
    			{
    				cout<<cyan<<"║ ";
    				if (Board[x][y][0]<10) cout<<" ";
    				if (Board[x][y][0]<76) cout<<" ";
    				if ((x==posx)&&(y==posy)) cout<<blue;
    				else if (Board[x][y][0]==0) cout<<red;
    				else
    					cout<<normal;
    					cout<<Board[x][y][0];
    			}
    		cout<<cyan<<"║\n";
    	}
    	 cout<<cyan<<"╚════╩════╩════╩════╩════╝\n"<<normal;
    	cout<<"\n\n";
    	for (y=0;y<5;y++)
    	{
    		for (x=0;x<5;x++)
    		{
    			cout<<Board[x][y][1]<<" ";
    		}
    		cout<<"\n";
    	}
    	return 0;
    }
    ///////////////////////////////////////////////////////////////////////
    int DetectBingo(int Board[5][15][2])
    {
    	int x,y,loseH,loseV,loseD1,loseD2;
    	for (y=0;y<5;y++)
    	{
    		loseH=0;
    		loseV=0;
    		loseD1=0;
    		loseD2=0;
    		for (x=0;x<5;x++)
    		{
    			loseH=Board[x][y][0];
    			loseV=Board[x][y][0];
    			loseD1+=Board[x][y][0];
    			loseD2+=Board[4-x][y][0];
    		}
    		if (!loseH) cout<<Board[x][0][0]<<Board[0][y][0]<<"BINGO!";
    		if (!loseV) cout<<"Bingo!";
    		if (!loseD1)cout<<"Bingo!";
    		if (!loseD2)cout<<"Bingo!";
    	}
    	return 0;
    }
    ///////////////////////////////////////////////////////////////////////
    int main()
    {
    	int x=2,y=2,Board[5][15][2],input;
    	MakeCard(Board);
    	do
    	{
    		system("clear");
    		Color(Board,x,y);
    		system("sleep .01");
    		input=toupper(getch());
    		if (input=='D') x++;
    		if (input=='A') x--;
    		if (input=='S') y++;
    		if (input=='W') y--;
    		if (input==' ') 
    		{
    			if (Board[x][y][0]!=0)
    			{
    				Board[x][y][1]=Board[x][y][0];
    				Board[x][y][0]=0;
    			}
    		}
    	}while ((input!=27)||(DetectBingo(Board)));
    	//Declare Variables
    	//Input
    	//Calculations
    	//Output
    	return 0;
    }

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    704
    Your code is C++, not C. This is a C programming forum. Try posting in the C++ forum.

    You should also avoid the use of getch(). There are better ways of getting input.

  3. #3
    Registered User
    Join Date
    May 2018
    Posts
    4
    Sorry I thought I was in C++ forum

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,745
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bingo Card Logic (no repetition)
    By Renan Jacomassi in forum C Programming
    Replies: 5
    Last Post: 02-15-2016, 12:02 AM
  2. Having problem with a program for Bingo
    By Magmadragoon in forum C Programming
    Replies: 13
    Last Post: 05-04-2011, 07:20 PM
  3. Bingo with words
    By smitty007 in forum C Programming
    Replies: 19
    Last Post: 04-14-2009, 05:14 PM
  4. Bingo Card Program. Any input?
    By dukebdx12 in forum C++ Programming
    Replies: 5
    Last Post: 02-15-2008, 03:00 PM

Tags for this Thread