#include <iostream>
#include <cstdlib>
#include <vector>
#include <ctime>
#include <limits> 

using namespace std;
// returns a random integer within the specified inclusive range [min, max]

int generateRandomNumber(int min, int max) {
    return min + rand() % (max - min + 1);
}

// generates a 2D vector representing player cards for a given number of players, rows, and columns. 

vector<vector<int>> generatePlayerCards(int numOfPlayers, int numOfRows, int numOfColumns) {
    vector<vector<int>> playerCards(numOfPlayers, vector<int>(numOfRows * numOfColumns, 0));

    for (int i = 0; i < numOfPlayers; i++) {
        vector<vector<int>> columns(numOfColumns, vector<int>());

        for (int j = 0; j < numOfColumns; j++) {
            int columnMin = j * 15 + 1;
            int columnMax = (j + 1) * 15;

            vector<int> columnNumbers;
            while (columnNumbers.size() < numOfRows) {
                int number = generateRandomNumber(columnMin, columnMax);

            // Additional logic may go here to handle duplicates, if needed.

                bool alreadyExists = false;
                for (int k = 0; k < columnNumbers.size(); k++) {
                    if (columnNumbers[k] == number) {
                        alreadyExists = true;
                        break;
                    }
                }

                if (!alreadyExists) {
                    columnNumbers.push_back(number);
                }
            }

        // Assign the generated numbers to the j-th column of the i-th player.

            columns[j] = columnNumbers;
        }
//  Assigns the generated numbers to the appropriate positions in the playerCards

        for (int j = 0; j < numOfRows; j++) {           // Iterates through each row of the player's cards (from 0 to numOfRows - 1).
            for (int k = 0; k < numOfColumns; k++) {   // Iterates through each column of the player's cards (from 0 to numOfColumns - 1).
                playerCards[i][j * numOfColumns + k] = columns[k][j]; 
            }
        }


        
    }

    return playerCards;
}

void displayPlayerCards(const vector<vector<int>>& playerCards, int numOfRows, int numOfColumns) {
    for (int i = 0; i < playerCards.size(); i++) {
        cout << "Player " << i + 1 << " Card:\n";
        cout << "+----+----+----+----+----+\n";
        for (int j = 0; j < numOfRows; j++) {
            for (int k = 0; k < numOfColumns; k++) {
                int middleRow = numOfRows / 2;
        int middleColumn = numOfColumns / 2;
                if (playerCards[i][j * numOfColumns + k] == 0) {
                    cout << "| XX ";
                } 
            else if (playerCards[i][j * numOfColumns + k] == -1) {
    cout << "| XX ";
}
                
                else {
                    cout << "| ";
                    if (playerCards[i][j * numOfColumns + k] < 10) {
                        cout << " ";
                    }
                    cout << playerCards[i][j * numOfColumns + k] << " ";
                }
            }
            cout << "|\n";
            cout << "+----+----+----+----+----+\n";
        }
        cout << endl;
    }
}

//This function updates the player cards by marking drawn numbers.


void updatePlayerCards(vector<vector<int>>& playerCards, int numOfPlayers, int numOfRows, int numOfColumns, int number) {
    for (int i = 0; i < numOfPlayers; i++) {
        for (int j = 0; j < numOfRows * numOfColumns; j++) {
            if (playerCards[i][j] == number) {
                playerCards[i][j] = 0;
            }
        }
    }
}

int checkWin(const vector<vector<int>>& playerCards, int numOfRows, int numOfColumns) {

    for (int i = 0; i < playerCards.size(); i++) {
        for (int j = 0; j < numOfRows; j++) {
            bool isRowComplete = true;
            for (int k = 0; k < numOfColumns; k++) {
                if (playerCards[i][j * numOfColumns + k] != 0) {
                    isRowComplete = false;
                    break;
                }
            }
            if (isRowComplete) {
                return i;  // Player i wins
            }
        }
    }


    for (int i = 0; i < playerCards.size(); i++) {
        for (int j = 0; j < numOfColumns; j++) {
            bool isColumnComplete = true;
            for (int k = 0; k < numOfRows; k++) {
                if (playerCards[i][k * numOfColumns + j] != 0) {
                    isColumnComplete = false;
                    break;
                }
            }
            if (isColumnComplete) {
                return i;  // Player i wins
            }
        }
    }

bool isDiagonalComplete1 = true;
bool isDiagonalComplete2 = true;
for (int i = 0; i < numOfRows; i++) {
    if (playerCards[0][i * numOfColumns + i] != 0) {
        isDiagonalComplete1 = false;
    }
    if (playerCards[0][(numOfRows - i - 1) * numOfColumns + i] != 0) {
        isDiagonalComplete2 = false;
    }
}
if (isDiagonalComplete1) {
    return 0;  // Player 0 wins
}
if (isDiagonalComplete2) {
    return playerCards.size() - 1;  // Last player wins
}

    return -1;  // No winner yet
}

bool checkAllCardsEmpty(const vector<vector<int>>& playerCards) {
    for (int i = 0; i < playerCards.size(); i++) {
        for (int j = 0; j < playerCards[i].size(); j++) {
            if (playerCards[i][j] != 0) {
                return false;
            }
        }
    }
    return true;
}

#include <iostream>
#include <cstdlib>
#include <vector>
#include <ctime>

using namespace std;


int main() {
    int numOfPlayers = 4;
    int numOfRows = 5;
    int numOfColumns = 5;

    vector<vector<int>> playerCards = generatePlayerCards(numOfPlayers, numOfRows, numOfColumns);

    bool gameWon = false;
    int numbersDrawn = 0;
    vector<int> drawnNumbers;

    bool exitGame = false;

    while (!exitGame) {
        cout <<"\n";
        cout << " *";
cout << "   _________________________________________________________________________________________________________________" << endl;
cout << "   _________________________________________________________________________________________________________________" << endl;
cout << "   | |                                                                                                           | |" << endl;
cout << "   | |                                                                                                           | |" << endl;
cout << "   | |     /$$$$$$$  /$$$$$$ /$$   /$$  /$$$$$$   /$$$$$$         /$$$$$$   /$$$$$$  /$$      /$$ /$$$$$$$$      | |" << endl;
cout << "   | |    | $$__  $$|_  $$_/| $$$ | $$ /$$__  $$ /$$__  $$       /$$__  $$ /$$__  $$| $$$    /$$$| $$_____/      | | " << endl;
cout << "   | |    | $$   \ $$  | $$  | $$$$| $$| $$   \__/| $$   \ $$      | $$  \__/|  $$  \  $$| $$$$  /$$$$| $$            | |" << endl;
cout << "   | |    | $$$$$$$   | $$  | $$ $$ $$| $$ /$$$$| $$   |$$      | $$ /$$$$| $$$$$$$$| $$ $$/$$ $$| $$$$$         | |" << endl;
cout << "   | |    | $$__  $$  | $$  | $$  $$$$| $$|_  $$| $$   |$$      | $$|_  $$| $$__  $$| $$  $$$| $$| $$__/         | |"<< endl;
cout << "   | |    | $$   \ $$  | $$  | $$ \  $$$| $$  \ $$|  $$   |$$      | $$  \  $$| $$  | $$| $$\   $ | $$| $$            | |" << endl;
cout << "   | |    | $$$$$$$/ /$$$$$$| $$  \  $$|  $$$$$$/|  $$$$$$/      |  $$$$$$/| $$  | $$| $$ \/   | $$| $$$$$$$$      | | " << endl;
cout << "   | |    |_______/ |______/|__/   __/  ______/   \______/        \______/ |__/  |__/|__/     |__/ |________/      | |" << endl;
cout << "   | |                                                                                                           | |" << endl;
cout << "   | |                                                                                                By: Cholo  | |" << endl;
cout << "   _________________________________________________________________________________________________________________" << endl;
cout << "   _________________________________________________________________________________________________________________" << endl;
     cout <<"\n";
           



        cout << "1. Draw a number\n";
        cout << "2. Display player cards\n";
        cout << "3. Check for a win\n";
        cout << "4. Automatically draw numbers until a player wins\n";
        cout << "5. Exit\n";
        cout << "Enter your choice: ";

        srand(static_cast<unsigned int>(time(0))); // This seeds the random number generator with the current time to ensure different random numbers on each program run.



        int choice;
        cin >> choice; //This gets the user's choice from the menu.

        switch (choice) {                     // ... cases for different menu options (xecutes different blocks of code based on the user's choice.)
            case 1: {
                int number = generateRandomNumber(1, 75);
                bool alreadyDrawn = false;
                for (int i = 0; i < drawnNumbers.size(); i++) {
                    if (drawnNumbers[i] == number) {
                        alreadyDrawn = true;
                        break;
                    }
                }
                if (alreadyDrawn) {
                    continue;
                }
                drawnNumbers.push_back(number);
                updatePlayerCards(playerCards, numOfPlayers, numOfRows, numOfColumns, number);
                cout << "Number drawn: " << number << endl;
                numbersDrawn++;
                if (checkWin(playerCards, numOfRows, numOfColumns) != -1) {
                    gameWon = true;
                }
                break;
            }
            case 2: {
                // Display player cards
                displayPlayerCards(playerCards, numOfRows, numOfColumns);
                break;
            }
            case 3: {
                // Check for a win
                int winner = checkWin(playerCards, numOfRows, numOfColumns);
                if (winner != -1) {
                            cout <<"\n" ;                   
    cout << "                            .''.\n";
    cout << "       .''             *''*    :_\\/_:     .\n";
    cout << "      :_\\/_:   .    .:.*_\\/_*   : /\\ :  .'.:.'. \n";
    cout << "  .''.: /\\ : _\\(/_  ':'* /\\ *  : '..'.  -=:o:=- \n";
    cout << " :_\\/_:'.:::. /)\\*''*  .|.* '.\\'/.'_\\(/_'.':'.  \n";
    cout << " : /\\ : :::::  '*_\\/_* | |  -= o =- /)\\    '  *  \n";
    cout << "  '..'  ':::'   * /\\ * |'|  .'/.\\'.  '._____\n";
    cout << "      *        __*..* |  |     :      |.   |' .---\"|\n";
    cout << "       _*   .-'   '-. |  |     .--'|  ||   | _|    |\n";
    cout << "    .-'|  _.|  |    ||   '-__  |   |  |    ||      |\n";
    cout << "    |' | |.    |    ||       | |   |  |    ||      |\n";
    cout << " ___|  '-'     '    \"\"       '-'   '-.'    '`      |____\n";
    cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
                        cout << "       Congratulations Player " << winner + 1 << "! You have won!\n";
                            cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
                      cout <<"\n" ;   
                   
                    gameWon = true;
                } else {
                    cout << "No player has won yet.\n";
                }
                break;
            }
            case 4: {
                // Automatically draw numbers until a player wins
                while (!gameWon && numbersDrawn < 75) {
                    int number = generateRandomNumber(1, 75);
                    bool alreadyDrawn = false;

                    for (int i = 0; i < drawnNumbers.size(); i++) {
                        if (drawnNumbers[i] == number) {
                            alreadyDrawn = true;
                            break;
                        }
                
                    }

                    if (alreadyDrawn) {
                        continue;
                    }

                    drawnNumbers.push_back(number);
                    updatePlayerCards(playerCards, numOfPlayers, numOfRows, numOfColumns, number);
                    cout << "Number drawn: " << number << endl;
                    numbersDrawn++;
                    int winner = checkWin(playerCards, numOfRows, numOfColumns);
                    if (winner != -1) {
                                                                 cout <<"\n" ;                   

                        cout << " 88888888ba  88 888b      88   ,ad8888ba,    ,ad8888ba," << endl;
    cout << " 88      \"8b 88 8888b     88  d8\"'    `\"8b  d8\"'    `\"8b" << endl;
    cout << " 88      ,8P 88 88 `8b    88 d8'           d8'        `8b" << endl;
    cout << " 88aaaaaa8P' 88 88  `8b   88 88            88          88" << endl;
    cout << " 88\"\"\"\"\" 8b, 88 88   `8b  88 88     888888 88          88" << endl;
    cout << " 88      `8b 88 88    `8b 88 Y8,        88 Y8,        ,8P" << endl;
    cout << " 88      a8P 88 88     `8888  Y8a.    .a88  Y8a.    .a8P" << endl;
    cout << " 88888888P\"  88 88      `888   `\"Y88888P\"    `\"Y8888Y\"'" << endl;   
                                         cout <<"\n" ;                   

                        gameWon = true;
                   ;                    



                        displayPlayerCards(playerCards, numOfRows, numOfColumns);
                    }
                }
                break;
            }
            case 5: {
                cout << "\nExiting the game.\n";
                cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡤⠒⠒⠢⢄⡀⠀⠀⢠⡏⠉⠉⠉⠑⠒⠤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡞⠀⠀⠀⠀⠀⠙⢦⠀⡇⡇⠀⠀⠀⠀⠀⠀⠈⠱⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠊⠉⠉⠙⠒⢤⡀⠀⣼⠀⠀⢀⣶⣤⠀⠀⠀⢣⡇⡇⠀⠀⢴⣶⣦⠀⠀⠀⢳⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⠀⠀⠀⢀⣠⠤⢄⠀⠀⢰⡇⠀⠀⣠⣀⠀⠀⠈⢦⡿⡀⠀⠈⡟⣟⡇⠀⠀⢸⡇⡆⠀⠀⡼⢻⣠⠀⠀⠀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⠀⢀⠖⠉⠀⠀⠀⣱⡀⡞⡇⠀⠀⣿⣿⢣⠀⠀⠈⣧⣣⠀⠀⠉⠋⠀⠀⠀⣸⡇⠇⠀⠀⠈⠉⠀⠀⠀⢀⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⣠⠏⠀⠀⣴⢴⣿⣿⠗⢷⡹⡀⠀⠘⠾⠾⠀⠀⠀⣿⣿⣧⡀⠀⠀⠀⢀⣴⠇⣇⣆⣀⢀⣀⣀⣀⣀⣤⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⣿⠀⠀⢸⢻⡞⠋⠀⠀⠀⢿⣷⣄⠀⠀⠀⠀⠀⣠⡇⠙⢿⣽⣷⣶⣶⣿⠋⢰⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⡿⡄⠀⠈⢻⣝⣶⣶⠀⠀⠀⣿⣿⣱⣶⣶⣶⣾⡟⠀⠀⠀⢈⡉⠉⢩⡖⠒⠈⠉⡏⡴⡏⠉⠉⠉⠉⠉⠉⠉⠉⡇⠀⠀⢀⣴⠒⠢⠤⣀\n";
    cout << "⢣⣸⣆⡀⠀⠈⠉⠁⠀⠀⣠⣷⠈⠙⠛⠛⠛⠉⢀⣴⡊⠉⠁⠈⢢⣿⠀⠀⠀⢸⠡⠀⠁⠀⠀⠀⣠⣀⣀⣀⣀⡇⠀⢰⢁⡇⠀⠀⠀⢠\n";
    cout << "⠀⠻⣿⣟⢦⣤⡤⣤⣴⣾⡿⢃⡠⠔⠒⠉⠛⠢⣾⢿⣿⣦⡀⠀⠀⠉⠀⠀⢀⡇⢸⠀⠀⠀⠀⠀⠿⠿⠿⣿⡟⠀⢀⠇⢸⠀⠀⠀⠀⠘\n";
    cout << "⠀⠀⠈⠙⠛⠿⠿⠿⠛⠋⢰⡋⠀⠀⢠⣤⡄⠀⠈⡆⠙⢿⣿⣦⣀⠀⠀⠀⣜⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⢀⠃⠀⡸⠀⠇⠀⠀⠀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⢣⠀⠀⠈⠛⠁⠀⢴⠥⡀⠀⠙⢿⡿⡆⠀⠀⢸⠀⢸⢰⠀⠀⠀⢀⣿⣶⣶⡾⠀⢀⠇⣸⠀⠀⠀⠀⢠⠇⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⡀⢇⠀⠀⠀⢀⡀⠀⠀⠈⢢⠀⠀⢃⢱⠀⠀⠀⡇⢸⢸⠀⠀⠀⠈⠉⠉⠉⢱⠀⠼⣾⣿⣿⣷⣦⠴⠀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢱⠘⡄⠀⠀⢹⣿⡇⠀⠀⠈⡆⠀⢸⠈⡇⢀⣀⣵⢨⣸⣦⣤⣤⣄⣀⣀⣀⡞⠀⣠⡞⠉⠈⠉⢣⡀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢃⠘⡄⠀⠀⠉⠀⠀⣠⣾⠁⠀⠀⣧⣿⣿⡿⠃⠸⠿⣿⣿⣿⣿⣿⣿⠟⠁⣼⣾⠀⠀⠀⠀⢠⠇⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣤⣿⡿⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠀⠀⠀⠀⠀\n";

                exitGame = true;
                break;
            }
            default: {
                cout << "Invalid choice. Please try again.\n"; 
                cin.clear();  // Clear the error flag
            cin.ignore(numeric_limits<streamsize>::max(), '\n');  // Discard invalid input 
            continue;  // Continue the loop to re-display the menu
                continue;
            }
            break;
        }

        // Check if the game is won or all numbers are drawn
        if (!exitGame && (gameWon || numbersDrawn >= 75)) {
            if (gameWon) {
                int winner = checkWin(playerCards, numOfRows, numOfColumns);

                if (winner != -1) {
                     cout <<"\n" ;                   
    cout << "    .''.\n";
    cout << "        .''             *''*    :_\\/_:     .\n";
    cout << "       :_\\/_:   .    .:.*_\\/_*   : /\\ :  .'.:.'. \n";
    cout << "  .''.: /\\ : _\\(/_  ':'* /\\ *  : '..'.  -=:o:=- \n";
    cout << "  :_\\/_:'.:::. /)\\*''*  .|.* '.\\'/.'_\\(/_'.':'.  \n";
    cout << "  : /\\ : :::::  '*_\\/_* | |  -= o =- /)\\    '  *  \n";
    cout << "   '..'  ':::'   * /\\ * |'|  .'/.\\'.  '._____\n";
    cout << "       *        __*..* |  |     :      |.   |' .---\"|\n";
    cout << "        _*   .-'   '-. |  |     .--'|  ||   | _|    |\n";
    cout << "     .-'|  _.|  |    ||   '-__  |   |  |    ||      |\n";
    cout << "     |' | |.    |    ||       | |   |  |    ||      |\n";
    cout << "  ___|  '-'     '    \"\"       '-'   '-.'    '`      |____\n";
    cout << " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
                    cout << "         Congratulations Player " << winner + 1 << "! You have won!" << endl;
                        cout << " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
                         cout <<"\n" ;     
cout << " 88888888ba  88 888b      88   ,ad8888ba,    ,ad8888ba," << endl;
    cout << " 88      \"8b 88 8888b     88  d8\"'    `\"8b  d8\"'    `\"8b" << endl;
    cout << " 88      ,8P 88 88 `8b    88 d8'           d8'        `8b" << endl;
    cout << " 88aaaaaa8P' 88 88  `8b   88 88            88          88" << endl;
    cout << " 88\"\"\"\"\" 8b, 88 88   `8b  88 88     888888 88          88" << endl;
    cout << " 88      `8b 88 88    `8b 88 Y8,        88 Y8,        ,8P" << endl;
    cout << " 88      a8P 88 88     `8888  Y8a.    .a88  Y8a.    .a8P" << endl;
    cout << " 88888888P\"  88 88      `888   `\"Y88888P\"    `\"Y8888Y\"'" << endl;   
                                         cout <<"\n" ;                   

                } else {
                    cout << "Error: Unable to determine the winner." << endl;
                }
            } else {
                cout << "Nobody has won. It's a draw!" << endl;
            }

            // Ask if the user wants to play again or exit
            cout << "\n";
            cout << "Do you want to play again? (0 for Yes, 1 for No): "; // 
            cin >> exitGame; // gets the choice whether to re flash the menu (0) or exit the game (1)

            if (!exitGame) {
                // Reset game variables and generate new player cards
                playerCards = generatePlayerCards(numOfPlayers, numOfRows, numOfColumns);
                gameWon = false;
                numbersDrawn = 0;
                drawnNumbers.clear();
            }
            
            else {                                                               // if player decides to end the game this will execute
                   cout << "\n";
                cout << "\nExiting the game.\n";
                cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡤⠒⠒⠢⢄⡀⠀⠀⢠⡏⠉⠉⠉⠑⠒⠤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡞⠀⠀⠀⠀⠀⠙⢦⠀⡇⡇⠀⠀⠀⠀⠀⠀⠈⠱⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠊⠉⠉⠙⠒⢤⡀⠀⣼⠀⠀⢀⣶⣤⠀⠀⠀⢣⡇⡇⠀⠀⢴⣶⣦⠀⠀⠀⢳⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⠀⠀⠀⢀⣠⠤⢄⠀⠀⢰⡇⠀⠀⣠⣀⠀⠀⠈⢦⡿⡀⠀⠈⡟⣟⡇⠀⠀⢸⡇⡆⠀⠀⡼⢻⣠⠀⠀⠀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⠀⢀⠖⠉⠀⠀⠀⣱⡀⡞⡇⠀⠀⣿⣿⢣⠀⠀⠈⣧⣣⠀⠀⠉⠋⠀⠀⠀⣸⡇⠇⠀⠀⠈⠉⠀⠀⠀⢀⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⣠⠏⠀⠀⣴⢴⣿⣿⠗⢷⡹⡀⠀⠘⠾⠾⠀⠀⠀⣿⣿⣧⡀⠀⠀⠀⢀⣴⠇⣇⣆⣀⢀⣀⣀⣀⣀⣤⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⣿⠀⠀⢸⢻⡞⠋⠀⠀⠀⢿⣷⣄⠀⠀⠀⠀⠀⣠⡇⠙⢿⣽⣷⣶⣶⣿⠋⢰⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n";
    cout << "⡿⡄⠀⠈⢻⣝⣶⣶⠀⠀⠀⣿⣿⣱⣶⣶⣶⣾⡟⠀⠀⠀⢈⡉⠉⢩⡖⠒⠈⠉⡏⡴⡏⠉⠉⠉⠉⠉⠉⠉⠉⡇⠀⠀⢀⣴⠒⠢⠤⣀\n";
    cout << "⢣⣸⣆⡀⠀⠈⠉⠁⠀⠀⣠⣷⠈⠙⠛⠛⠛⠉⢀⣴⡊⠉⠁⠈⢢⣿⠀⠀⠀⢸⠡⠀⠁⠀⠀⠀⣠⣀⣀⣀⣀⡇⠀⢰⢁⡇⠀⠀⠀⢠\n";
    cout << "⠀⠻⣿⣟⢦⣤⡤⣤⣴⣾⡿⢃⡠⠔⠒⠉⠛⠢⣾⢿⣿⣦⡀⠀⠀⠉⠀⠀⢀⡇⢸⠀⠀⠀⠀⠀⠿⠿⠿⣿⡟⠀⢀⠇⢸⠀⠀⠀⠀⠘\n";
    cout << "⠀⠀⠈⠙⠛⠿⠿⠿⠛⠋⢰⡋⠀⠀⢠⣤⡄⠀⠈⡆⠙⢿⣿⣦⣀⠀⠀⠀⣜⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⢀⠃⠀⡸⠀⠇⠀⠀⠀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⢣⠀⠀⠈⠛⠁⠀⢴⠥⡀⠀⠙⢿⡿⡆⠀⠀⢸⠀⢸⢰⠀⠀⠀⢀⣿⣶⣶⡾⠀⢀⠇⣸⠀⠀⠀⠀⢠⠇⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⡀⢇⠀⠀⠀⢀⡀⠀⠀⠈⢢⠀⠀⢃⢱⠀⠀⠀⡇⢸⢸⠀⠀⠀⠈⠉⠉⠉⢱⠀⠼⣾⣿⣿⣷⣦⠴⠀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢱⠘⡄⠀⠀⢹⣿⡇⠀⠀⠈⡆⠀⢸⠈⡇⢀⣀⣵⢨⣸⣦⣤⣤⣄⣀⣀⣀⡞⠀⣠⡞⠉⠈⠉⢣⡀⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢃⠘⡄⠀⠀⠉⠀⠀⣠⣾⠁⠀⠀⣧⣿⣿⡿⠃⠸⠿⣿⣿⣿⣿⣿⣿⠟⠁⣼⣾⠀⠀⠀⠀⢠⠇⠀⠀\n";
    cout << "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣤⣿⡿⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠀⠀⠀⠀⠀\n";

        }
    }
}
    return 0;
} 

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

if(conditional-expression) {
   //code
}
else {
   //code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression){    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
......    
    
default:     
 code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
// code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
 // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}