c++ arrays

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>
using namespace std;

int main()
{
	const int NUMBER_OF_CARDS = 52;
	int deck[NUMBER_OF_CARDS];
	string suits[] = { "Spades", "Hearts", "Diamonds","Clubs" };
	string ranks[] = { "Ace","2","3","4","5","6","7","8","9","10""Jack","King","Queen" };

	for (int  i = 0; i < NUMBER_OF_CARDS; i++)
	
		deck[i] = i;

		srand(time(0));

	for (size_t i = 0; i < NUMBER_OF_CARDS; i++)
		{
		int index = rand() % NUMBER_OF_CARDS;
		int temp = deck[i];
		deck[i] = deck[index];
		deck[index] = temp;
		}
	for (int i = 0; i < 4; i++)
	{
		string suit = suits[deck[i] / 13];
		string rank = ranks[deck[i] % 13];
		cout << "Card Number " << deck[i] << ": "
			<< rank << " of " << suit << endl;
	}
	return 0;

}
#include<iostream>
#include <fstream>
#include <cctype>
#include<ctffunc.h>
using namespace std;

void enterLetters(char list[], int limit);
void countVandCLetters(char list[], int limit);



const int LIMIT = 100;


int main()
{
	char letters[LIMIT];

	enterLetters(letters, LIMIT);
	countVandCLetters(letters, LIMIT);
    
}
void enterLetters(char list[], int limit)
{
	
	for (int i = 0; i < limit; i++)
	{
		cin >> list[i];
		if (list[i] == '0')
			break;
	}
}
void countVandCLetters(char list[], int limit)
{
	int vowel = 0;
	int Consonant = 0;
	char vowels[] = { 'a','e','o','u','i' };
	char Consonants[] = { 'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z' };
	
	for (int i = 0; i < limit; i++)
	{
		if (IsCharUpperA(list[i]))
			list[i] = list[i] + 32;
		
		for (int j = 0; j < 5; j++)
		{
			if (list[i] == vowels[j])
				vowel++;
		}
		for (int j = 0; j < 21; j++)
		{
			
			if (list[i] == Consonants[j])
				Consonant++;
		}
		
		
	}
	
		cout << "Number Of vowels Letters is " << vowel << endl;
		cout << "Number Of Consonants Letters is " << Consonant << endl;
	
}
 int list[LIMIT], i, j, val, count, flag, test[LIMIT], c = 0;
    //enter the values
    for (i = 0; i < LIMIT; i++)
    {
        cout << "Enter The Elements : ";
        cin >> list[i];
        if (list[i] == 0)
            break;
    }
    //count the occurence of each value
    for (j = 0; j < LIMIT; j++)
    {
        count = 0;
        flag = 1;
        val = list[j];
        //counts each value's occurence and if the value is 0 break
        for (i = 0; i < LIMIT; i++)
        {
            if (val == list[i])
                count++;
            else if (list[i] == 0)
                break;
        }
        //checks whether the value has been already counted (flag = 0) or not (flag stays 1)
        for (i = 0; i < c; i++)
        {
            if (test[i] == val)
                flag = 0;
        }
        //if the value has not been counted print 
        if (flag == 1)
        {

            cout << "The Occurence Of The Number " << val << " is " << count << endl;
            test[c] = val;
            c++;
        }

    }
#include <iostream>
#include<iomanip>

using namespace std;
void eightQueens(char board[], int size);
void shuffle(char list[], int size);
int linearSearch(char list[], char key, int arraySize);
int linearSearchInt(int list[], int key, int arraySize);




const int SIZE = 8;
int main()
{	char board[SIZE];

	srand(unsigned( time(0)));
	int x = rand()%SIZE;
	for (int i = 0; i < SIZE; i++)
	{
		if (i == x)
			board[i] = 'Q';
		else
			board[i] = ' ';
	}
		eightQueens(board, SIZE);
}
void eightQueens(char board[],int size)
{
	int count = 0, vale, test[SIZE];
	for (int i = 0; i < size ; i++)
	{
		 vale = linearSearch(board, 'Q', size);
		 bool flage = true;
		 
		for (int j = 0; j < count;j++)
		{
			if (test[j] == vale)
				flage = false;
		}
		if (flage == true)
		{
			for (int j = 0; j < size; j++)
			{
				cout  << "|";
				cout << board[j];
			}
			test[count] = vale;
			count++;
			shuffle(board, size);
		}
		else
		{
			int n = 0;
			for (int j = 0; j < 100; j++)
			{
				shuffle(board, size);
				if (linearSearchInt(test, linearSearch(board, 'Q', size), size) == -1)
				{
					n = linearSearch(board, 'Q', size);
					test[count] = n;
					count++;
					break;
				}
			}
			for (int j = 0; j < SIZE; j++)
			{
				if (j == n)
					board[j] = 'Q';
				else
					board[j] = ' ';
			}
			for (int j = 0; j < size; j++)
			{
				cout << "|";
				cout << board[j] ;
			}
			

		}
		cout <<'|'<< endl;
	}
	
}

int linearSearch( char list[], char key, int arraySize)
{
	for (int i = 0; i < arraySize; i++)
	{
			if (key == list[i])
				return i;
	}
	return -1;
}
int linearSearchInt(int list[], int key, int arraySize)
{
	for (int i = 0; i < arraySize; i++)
	{
		if (key == list[i])
			return i;
	}
	return -1;
}
void shuffle(char list[], int size)
{
	
	for (int i = size - 1; i > 0; i--)
	{
		// Generate an index j randomly with 0 <= j <=i
		int j = rand() % (i + 1);
		// Swap myList[i] with myList[j]
		char temp = list[i];
		list[i] = list[j];
			list[j] = temp;
	}
}



	
	


#include <iostream>
#include<iomanip>
#include <string>

using namespace std;

void partisons(int list[], int listSize);


int main() 
{
	const int size1 = 6;
	
	
	int list1[size1];
	for (int i = 0; i <size1 ; i++)
	{
		cin >> list1[i];
	}
	 selectionSort(list1, size1);

	
	for (int i = 0; i < size1; i++)
	{
		cout << list1[i] << " ";
	}

	
}

void partisons(int list[], int listSize)
{
    int first = 0;
    int low = first + 1;
    int high = listSize - 1;
    int pivot = list[first];

    while (high > low) {

        while (low <= high && list[low] <= pivot)
        {
            low++;
        }
        while (low <= high && list[high] > pivot)
        {
            high--;
        }
        if (high > low) {
            int temp = list[high];
            list[high] = list[low];
            list[low] = temp;
        }
    }

    while (high >= low && list[high] >= pivot) high--;

    if (high > first) {
        int temp = list[high];
        list[high] = list[first];
        list[first] = temp;
        
    }
    
	 }
	
	


#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int octal2Dec(string& octal);
bool validity(int number);
int stringToNum(string number);
int bin2Dec(int binNumber);
int dec2octal(const string& number);



void readASolution(int grid[][9]);
 bool isValid(const int grid[][9]);
 bool isValid(int i, int j, const int grid[][9]);

 int main()
{
	 // Read a Sudoku puzzle
		 int grid[9][9];
	 readASolution(grid);
	
		 cout << (isValid(grid) ? "Valid solution" : "Invalid solution");
	
		 return 0;
		 system("pause");
 }

 // Read a Sudoku puzzle from the keyboard
 void readASolution(int grid[][9])
 {
	 cout << "Enter a Sudoku puzzle:" << endl;
	 for (int i = 0; i < 9; i++)
		 for (int j = 0; j < 9; j++)
		 cin >> grid[i][j];
 }
 bool isValid(const int grid[][9])
	 {
	  for (int i = 0; i < 9; i++) 
		  for (int j = 0; j < 9; j++)
		  if (grid[i][j] < 1 || grid[i][j] > 9 ||
			  !isValid(i, j, grid))
		  return false;
	 
		  return true; // The fixed cells are valid
 }
 
	  // Check whether grid[i][j] is valid in the grid
 bool isValid(int i, int j, const int grid[][9])
 {
	 // Check whether grid[i][j] is valid at the i's row
	 for (int column = 0; column < 9; column++)
		 if (column != j && grid[i][column] == grid[i][j])
			 return false;

	 // Check whether grid[i][j] is valid at the j's column
	 for (int row = 0; row < 9; row++)
		 if (row != i && grid[row][j] == grid[i][j])
			 return false;

	 // Check whether grid[i][j] is valid in the 3-by-3 box
	 for (int row = (i / 3) * 3; row < (i / 3) * 3 + 3; row++)
		 for (int col = (j / 3) * 3; col < (j / 3) * 3 + 3; col++)
			 if (row != i && col != j && grid[row][col] == grid[i][j])
				 return false;

	 return true; // The current value at grid[i][j] is valid
 }
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;


void sortRowWise(int m[][4],
    int r, int c)
{
    // loop for rows of matrix
    for (int i = 0; i < r; i++)
    {
        // loop for column of matrix
        for (int j = 0; j < c; j++)
        {
            // loop for comparison and swapping
            for (int k = 0; k < c - j - 1; k++)
            {
                if (m[i][k] > m[i][k + 1])
                {
                    // swapping of elements
                    swap(m[i][k], m[i][k + 1]);
                }
            }
        }
    }

    // printing the sorted matrix
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
            cout << m[i][j] << " ";
        cout << endl;
    }
}

// Driver code
int main()
{
    int m[4][4];
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            cin >> m[i][j];
        }
    }
    int r = sizeof(m[0]) / sizeof(m[0][0]);
    int c = sizeof(m) / sizeof(m[0]);
    sortRowWise(m, r, c);
    return 0;
}
//(Financial application: compute tax) Rewrite Listing 3.3, ComputeTax.cpp,
//using arrays. For each filing status, there are six tax rates. Each rate is applied
//to a certain amount of taxable income. For example, from the taxable income
//of $400,000 for a single filer, $8,350 is taxed at 10%, (33,950–8,350) at 15%,
//(82,250–33,950) at 25%, (171,550–82,550) at 28%, (372,550–82,250) at
//33%, and (400,000–372,950) at 36%. The six rates are the same for all filing
//statuses, which can be represented in the following array:
//double rates[] = {0.10, 0.15, 0.25, 0.28, 0.33, 0.36};
//The brackets for each rate for all the filing statuses can be represented in a twodimensional array as follows:
//i//nt brackets[4][5] =
//{
// {8350, 33950, 82250, 171550, 372950}, // Single filer
// //{16700, 67900, 137050, 20885, 372950}, // Married jointly
 // or qualifying
 // widow(er)
// {8350, 33950, 68525, 104425, 186475}, // Married separately
// {11950, 45500, 117450, 190200, 372950} // Head of household
//};
//Suppose the taxable income is $400,000 for single filers. The tax can be computed
//as follows:
//tax = brackets[0][0] * rates[0] +
// (brackets[0][1] – brackets[0][0]) * rates[1] +
 //(brackets[0][2] – brackets[0][1]) * rates[2] +
// (brackets[0][3] – brackets[0][2]) * rates[3] +
// (brackets[0][4] – brackets[0][3]) * rates[4] +
// (400000 – brackets[0][4]) * rates[5]


#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

double computeTax(int brackets[][5], double rates[],
    int status, double income);
int getStatus();


// Driver code
int main()
{
    double rates[] = { 0.10, 0.15, 0.25, 0.28, 0.33, 0.36 };

    int brackets[4][5] =
    {
     {8350, 33950, 82250, 171550, 372950}, // Single filer
     {16700, 67900, 137050, 20885, 372950}, // Married jointly
     // or qualifying
     // widow(er)
     {8350, 33950, 68525, 104425, 186475}, // Married separately
     {11950, 45500, 117450, 190200, 372950} // Head of household
    };
    
     cout << "(1-single filer, 2-married jointly, "
         << "or qualifying widow(er), " << endl
         << "3-married separately, 4-head of household)" << endl
         << "Enter the filing status: ";
     int status = getStatus();
 cout<< "Enter the taxable income: ";
 double income;
 cin >> income;
    cout << "The tax for your income " << income << " is " << computeTax(brackets, rates, status, income);
}

double computeTax(int brackets[][5], double rates[],
    int status, double income) {
    double tax = 0, incomeTaxed = 0;
    for (int i = 4; i >= 0; i--) {
        if (income > brackets[status][i])
            tax += (incomeTaxed = income - brackets[status][i]) * rates[i + 1];
        income -= incomeTaxed;
    }
    return tax += brackets[status][0] * rates[0];
}
int getStatus() {
   
    int status;
    do {
        cin >> status;
        if (status < 0 || status > 3)
            cout<<"Error: invalid status";
    } while (status < 0 || status > 3);
    return status;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;




void decToBinary(int n)
{
    // array to store binary number 
    int binaryNum[3][3];
    
    //converting to binary 
    for (int i = 0; i < 3; i++) 
    {
        for (int j = 0; j < 3; j++)
        {
            binaryNum[i][j] = n % 2;
            n = n / 2;

        }
     }       

    // printing binary> array in reverse order 
    for (int i = 3-1; i >= 0; i--){
        for (int j = 3 - 1; j >= 0; j--)
        {
            if (binaryNum[i][j] == 0)
                cout << "H" << " ";
            else
                cout << "T" << " ";
        }
        cout << endl;
    }
    
 }

int main()
{
    int n;
    cout << "Enter a decimal number between 1 and 512 ";
    cin >> n;

    decToBinary(n);
    return 0;
}



#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;


bool  isConsecutiveFour(int values[][7]) {

    // checking rows
    for (int i = 0; i < 6; i++) {
       
        int current = values[i][0];
        int consecutiveCount = 0; // values[i][0] starts count

        for (int j = 0; j < 7; j++) {
            
            if (values[i][j] == current) {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                current = values[i][j];
                consecutiveCount = 1;
            }
        }
    }
    // check columns
    for (int j = 0; j < 7; j++) {
        
        int consecutiveCount = 0; // values[0][j] starts count
        int current = values[0][j];

        for (int i = 0; i < 6; i++) {

            if (values[i][j] == current) {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                current = values[i][j];
                consecutiveCount = 1;
            }

        }
    }

    // check topLeft side: going upright
    for (int i = 6 - 1; i > 0; i--) {
        int y = i;
        int x = 0;
        int consecutive = 0;
        int current = values[y][x];

        while (y >= 0) {
           
            if (values[y][x] == current) {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = values[y][x];
            }
            x++;
            y--;
        }
    }

    // check bottom right side: going upright
    for (int j = 0; j < 7; j++) {
        int y = 6 - 1;
        int x = j;
        int consecutive = 0;
        int current = values[y][x];

        while (x < 6 && y >= 0) {
            
            if (values[y][x] == current) {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = values[y][x];
            }
            x++;
            y--;
        }

    }

    // check bottom left side going up-left
    for (int j = 7 - 1; j > 0; j--) {

        int x = j;
        int y = 6 - 1;
        int current = values[y][x];
        int consecutiveCount = 0;

        while (x >= 0 && y >= 0) {

            if (values[y][x] == current) {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                consecutiveCount = 1;
                current = values[y][x];
            }

            x--;
            y--;
        }
    }
    // check bottom right side going up-left
    for (int row = 1; row < 6; row++) {
        int x = 7 - 1;
        int y = row;
        int consecutive = 0;
        int current = values[y][x];

        while (y >= 0) {
            
            if (values[y][x] == current) {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = values[y][x];
            }
            x--;
            y--;
        }

    }
    return false;
}






// Driver code
int main()
{
    int m[6][7];
    for (int i = 0; i < 6; i++)
        for (int j = 0; j < 7; j++)
            cin >> m[i][j];
    if (isConsecutiveFour(m) == true)
        cout << "true";
    else 
        cout << "false";
  
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>
#include <vector>

using namespace std;

bool  isConsecutiveFour(char grid[][7]) {

    // checking rows
    for (int i = 0; i < 6; i++)
    {
        char current = grid[i][0];
        int rowCnsec = 0;
        for (int j = 0; j < 7; j++)
        {
            if (current == grid[i][j] && grid[i][j] != ' ')
            {
                rowCnsec++;
                if (rowCnsec == 4) return true;
            }
            else
            {
                current = grid[i][j];
                rowCnsec = 1;
            }
        }
    }
    // check columns
    for (int j = 0; j < 7; j++)
    {
        char current = grid[0][j];
        int colConsec = 0;
        for (int i = 0; i < 6; i++)
        {
            if (current == grid[i][j] && grid[i][j] != ' ')
            {
                colConsec++;
                if (colConsec == 4) return true;
            }
            else
            {
                current = grid[i][j];
                colConsec = 1;
            }
        }
    }

    // check top Left side: going upright
    for (int i = 5; i >= 0 ; i--)
    {
        int consecutive = 0;
        int y = i;
        int x = 0;
        char current = grid[y][x];
        while (y >= 0)
        {
            if (grid[y][x] == current && grid[y][x] != ' ')
            {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else
            {
                consecutive = 1;
                current = grid[y][x];
            }
            x++;
            y--;
        }

    }
    // check bottom right side: going upright
    for (int j = 0; j < 7; j++) {
        int y = 6 - 1;
        int x = j;
        int consecutive = 0;
        int current = grid[y][x];

        while (x < 6 && y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = grid[y][x];
            }
            x++;
            y--;
        }

    }

    // check bottom left side going up-left
    for (int j = 7 - 1; j > 0; j--) {

        int x = j;
        int y = 6 - 1;
        int current = grid[y][x];
        int consecutiveCount = 0;

        while (x >= 0 && y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                consecutiveCount = 1;
                current = grid[y][x];
            }

            x--;
            y--;
        }
    }
    // check bottom right side going up-left
    for (int row = 1; row < 6; row++) {
        int x = 7 - 1;
        int y = row;
        int consecutive = 0;
        int current = grid[y][x];

        while (y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = grid[y][x];
            }
            x--;
            y--;
        }
    }
    return false;
}
// a function to show the grid
void show_grid(char grid[][7])
{
   
    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 7; j++)
        {
            cout << "|" << grid[i][j];
        }
        cout << "|" << endl;
    }
}

void player1(char grid[][7], int x, int y)
{
    show_grid(grid);
    
    cout << "Drop a red disk at column (0–6): ";
    cin >> y;
    if (grid[x][y] == ' ')
        grid[x][y] = 'R';
    else {
        //make sure not to target the same row
        while (grid[x][y] != ' ')x--;
        grid[x][y] = 'R';
    }
}

void player2(char grid[][7],int x,int y)
{
    show_grid(grid);

    cout << "Drop a yellow disk at column (0–6): ";
    cin >> y;
    if (grid[x][y] == ' ')
        grid[x][y] = 'Y';
    else {
        //make sure not to target the same row
        while (grid[x][y] != ' ')x--;
        grid[x][y] = 'Y';
    }
       
}
//check if it's a draw
bool is_draw(char grid[][7])
{
    for (int i = 0; i < 7; i++)
    {
      int count{0};
        if (grid[0][i] != ' ' && grid[1][i] != ' ' && grid[2][i] != ' '
            && grid[3][i] != ' ' && grid[4][i] != ' ' && grid[5][i] != ' ')
            count++;
      if(count == 6)
        return true;
        return false;
    }
}
int main()
{
	char grid[6][7];	
    //fill the grid with blank space
    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 7; j++)
        {
            grid[i][j] = ' ';
        }
    }
    //to check the winner
    bool winner1 = false;
    bool winner2 = false;

    while (!is_draw(grid))
    {
        int x{ 5 };
        int y{ 0 };
        player1(grid, x, y);
        if (isConsecutiveFour(grid))
        {
            winner1 = true;
            break;
        }
        player2(grid, x, y);
        if (isConsecutiveFour(grid))
        {
            winner2 = true;
            break;
        }
    }
    show_grid(grid);
    if (winner1 == true)
        cout << "player 1 wins ";
    else if (winner2 == true)
        cout << "player 2 wins ";
    else
        cout << "It's a draw ";

    
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>
#include <vector>

using namespace std;

bool  isConsecutiveFour(char grid[][7]) {

    // checking rows
    for (int i = 0; i < 6; i++)
    {
        char current = grid[i][0];
        int rowCnsec = 0;
        for (int j = 0; j < 7; j++)
        {
            if (current == grid[i][j] && grid[i][j] != ' ')
            {
                rowCnsec++;
                if (rowCnsec == 4) return true;
            }
            else
            {
                current = grid[i][j];
                rowCnsec = 1;
            }
        }
    }
    // check columns
    for (int j = 0; j < 7; j++)
    {
        char current = grid[0][j];
        int colConsec = 0;
        for (int i = 0; i < 6; i++)
        {
            if (current == grid[i][j] && grid[i][j] != ' ')
            {
                colConsec++;
                if (colConsec == 4) return true;
            }
            else
            {
                current = grid[i][j];
                colConsec = 1;
            }
        }
    }

    // check top Left side: going upright
    for (int i = 5; i >= 0 ; i--)
    {
        int consecutive = 0;
        int y = i;
        int x = 0;
        char current = grid[y][x];
        while (y >= 0)
        {
            if (grid[y][x] == current && grid[y][x] != ' ')
            {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else
            {
                consecutive = 1;
                current = grid[y][x];
            }
            x++;
            y--;
        }

    }
    // check bottom right side: going upright
    for (int j = 0; j < 7; j++) {
        int y = 6 - 1;
        int x = j;
        int consecutive = 0;
        int current = grid[y][x];

        while (x < 6 && y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = grid[y][x];
            }
            x++;
            y--;
        }

    }

    // check bottom left side going up-left
    for (int j = 7 - 1; j > 0; j--) {

        int x = j;
        int y = 6 - 1;
        int current = grid[y][x];
        int consecutiveCount = 0;

        while (x >= 0 && y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                consecutiveCount = 1;
                current = grid[y][x];
            }

            x--;
            y--;
        }
    }
    // check bottom right side going up-left
    for (int row = 1; row < 6; row++) {
        int x = 7 - 1;
        int y = row;
        int consecutive = 0;
        int current = grid[y][x];

        while (y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = grid[y][x];
            }
            x--;
            y--;
        }
    }
    return false;
}
// a function to show the grid
void show_grid(char grid[][7])
{
   
    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 7; j++)
        {
            cout << "|" << grid[i][j];
        }
        cout << "|" << endl;
    }
}

void player1(char grid[][7], int x, int y)
{
    show_grid(grid);
    
    cout << "Drop a red disk at column (0–6): ";
    cin >> y;
    if (grid[x][y] == ' ')
        grid[x][y] = 'R';
    else {
        //make sure not to target the same row
        while (grid[x][y] != ' ')x--;
        grid[x][y] = 'R';
    }
}

void player2(char grid[][7],int x,int y)
{
    show_grid(grid);

    cout << "Drop a yellow disk at column (0–6): ";
    cin >> y;
    if (grid[x][y] == ' ')
        grid[x][y] = 'Y';
    else {
        //make sure not to target the same row
        while (grid[x][y] != ' ')x--;
        grid[x][y] = 'Y';
    }
       
}
//check if it's a draw
bool is_draw(char grid[][7])
{
    for (int i = 0; i < 7; i++)
    {
      int count{0};
        if (grid[0][i] != ' ' && grid[1][i] != ' ' && grid[2][i] != ' '
            && grid[3][i] != ' ' && grid[4][i] != ' ' && grid[5][i] != ' ')
            count++;
      if(count == 6)
        return true;
        return false;
    }
}
int main()
{
	char grid[6][7];	
    //fill the grid with blank space
    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 7; j++)
        {
            grid[i][j] = ' ';
        }
    }
    //to check the winner
    bool winner1 = false;
    bool winner2 = false;

    while (!is_draw(grid))
    {
        int x{ 5 };
        int y{ 0 };
        player1(grid, x, y);
        if (isConsecutiveFour(grid))
        {
            winner1 = true;
            break;
        }
        player2(grid, x, y);
        if (isConsecutiveFour(grid))
        {
            winner2 = true;
            break;
        }
    }
    show_grid(grid);
    if (winner1 == true)
        cout << "player 1 wins ";
    else if (winner2 == true)
        cout << "player 2 wins ";
    else
        cout << "It's a draw ";

    
}

Similiar Collections

Python strftime reference pandas.Period.strftime python - Formatting Quarter time in pandas columns - Stack Overflow python - Pandas: Change day - Stack Overflow python - Check if multiple columns exist in a df - Stack Overflow Pandas DataFrame apply() - sending arguments examples python - How to filter a dataframe of dates by a particular month/day? - Stack Overflow python - replace a value in the entire pandas data frame - Stack Overflow python - Replacing blank values (white space) with NaN in pandas - Stack Overflow python - get list from pandas dataframe column - Stack Overflow python - How to drop rows of Pandas DataFrame whose value in a certain column is NaN - Stack Overflow python - How to drop rows of Pandas DataFrame whose value in a certain column is NaN - Stack Overflow python - How to lowercase a pandas dataframe string column if it has missing values? - Stack Overflow How to Convert Integers to Strings in Pandas DataFrame - Data to Fish How to Convert Integers to Strings in Pandas DataFrame - Data to Fish create a dictionary of two pandas Dataframe columns? - Stack Overflow python - ValueError: No axis named node2 for object type <class 'pandas.core.frame.DataFrame'> - Stack Overflow Python Pandas iterate over rows and access column names - Stack Overflow python - Creating dataframe from a dictionary where entries have different lengths - Stack Overflow python - Deleting DataFrame row in Pandas based on column value - Stack Overflow python - How to check if a column exists in Pandas - Stack Overflow python - Import pandas dataframe column as string not int - Stack Overflow python - What is the most efficient way to create a dictionary of two pandas Dataframe columns? - Stack Overflow Python Loop through Excel sheets, place into one df - Stack Overflow python - How do I get the row count of a Pandas DataFrame? - Stack Overflow python - How to save a new sheet in an existing excel file, using Pandas? - Stack Overflow Python Loop through Excel sheets, place into one df - Stack Overflow How do I select a subset of a DataFrame? — pandas 1.2.4 documentation python - Delete column from pandas DataFrame - Stack Overflow