poolet 0 Newbie Poster

Well my problem is on boardGenUSER I don't know why... it's print out the number 2 into the 0 row and 8th column :-/ I really
stuck and i need points to continue please check out my code below and let me know...

Thank you in advance!!!
Regards

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <stdlib.h>

using namespace std;


int row,col;
char board1[] = {']',']',']',']',']',']',']',']','\0'};
char board2[] = {'[','[','[','[','[','[','[','[','\0'};

int board[8][8] = {{0,0,0,0,9,0,0,0},
            {0,0,0,0,0,0,0,0},
            {9,0,9,0,0,0,9,0},
            {0,0,0,0,0,0,0,0},
            {0,9,0,9,0,0,0,0},
            {0,9,0,0,9,0,9,0},
            {0,0,0,0,0,0,0,0},
            {0,0,0,0,0,0,9,0}};


int quit();          //quit function of the game
int minesweep();
int replay();        //replay function of the game(if the user wants to quit)
int boardGenBOOM();  // board booms generating.... This function generate a specific type of booms into the 2D array
int boardGenUSER();   //board user generation..... This function generate the 2nd 2D array based on the user input Columns and Rows
int DisplayMenu();     //function that display the menu of the program

int main() { // Int main of the whole program...

    DisplayMenu();    //called the function
    return 0;   // a returning value (since compiler set warning message)
}

int quit()     //quit function
{
    char opt;   // declaration values

    do     // do of while loop below
    {
        cout << "Do you want to exit(y/n)? ";
        cin >> opt;    // asked from user to enter an input in char
if (opt=='n' || opt=='N')   // if statement.!! Checks if the input is == to a specific char
{
    cout << string(25, '\n'); // if it's not since I can't used cls am using linux distribution
    return main(); //rerurning into main menu           //  i set a string value of 25 and change line to clear the screen
}
    }while(opt!='Y' && opt!='y');   // while the input of the user is not = with the specific char (Y)-(y)
                                    // goes into do
return 0;  // returning value..!!
} // end of function quit!!!

int replay()   // replay function (when the game is done asking the user if wants to play again or not)
{
           char a;   //variables
           cout << "1) Replay 2) Quit" << endl;
           cin >> a;//asked from the user to set a char
           switch(a)  //switch case of the input that the user give....
           {  // started of switch case
                         case '1':    //case 1
                             return main();   //the program return into the main menu
                                    break;  //break of case 1
                         case '2':   //care 2
                                    cout << "Quit" << endl;
                                    break;  //break of case 2      //the program exit
                         default:          // default when the user enter invalid input..
                                    cout << "Invalid input" << endl;    //print out error message
                                    replay();                           // and return into the function replay (called the function)
                                    break;   //break  of default
           }   //end of switch case
           return 0; //returning value
}

int minesweep()         //MineSweep function
    {

    int counter =0;  //counter variable

        cout <<endl;
        cout<<"\n  | 0  1  2  3  4  5  6  7 |";         //prints out the columns
        cout<<"\n  | -  -  -  -  -  -  -  - |";
        for(int r = 0; r < 8; ++r)                      //for loop of rows
        {cout<<"\n";cout<<" "<<counter++<<"|";          //prints out the counter rows
        for(int c = 0; c < 8; ++c)                       //nested loop of columns
        cout <<" "<<board2[7]<<""<<board1[7]<<"";        // prints rows as board2 is - from 0 into 7
        }
cout<<endl;    //end line
boardGenUSER();   //called the function user board Generating to initial the user options
    return 0;

    }

int boardGenBOOM() //generating booms board.. This function generate the specific booms that are added into the board
    {  //start


            int counter =0;   // varibles
            char option;

            cout<<"\n    0  1  2  3  4  5  6  7 ";
            cout<<"\n    -  -  -  -  -  -  -  - ";  //prints out the columns
            for(int r = 0; r < 8; ++r)              //for loop for rows
            {cout<<"\n";cout<<" "<<counter++<<"|";   // prints out counter of rows
            for(int c = 0; c < 8; ++c)              // nested loop for columns
            cout <<" "<<board[r][c]<<" ";           //prints out array board rows and columns
            } //end of loop for
                            do // while the user enter N or n
                                {
                                    cout<<endl;
                                    cout << "Do you still want to play game(y/n)? ";
                                    cin >> option;  //asking again
                            if (option=='Y' || option=='y')   // if statement of 'y' or 'Y'
                            {                                 // if the user enters y or Y
                                cout << string(25, '\n');   //since I can't used system("CLS"); am using string 25 \n to enter 25 lines so
                                return main();    //and return into int main          // the screen will figuratively clear
                            }
                                }while(option!='N' && option!='n');   //while of option.. check if the user enter a char 'N'or'n'
            return 0;
}

int boardGenUSER(){

    int row,col;
    int counter =0;
    //int help1 = 1;
    int help2 = 2;
    //int help3 = 3;

    cout<<"Please enter row - column integers of cell: ";
    cin>>row>>col;

    cout<<""<<endl;

                    cout<<"\n  | 0  1  2  3  4  5  6  7 |";
                    cout<<"\n  | -  -  -  -  -  -  -  - |";

                    for(int r = 0; r < 8; ++r)
                    {cout<<"\n";cout<<" "<<counter++<<"|";
                                    for(int c = 0; c < 8; ++c)

                                        cout <<" "<<board2[r]<<""<<board1[c]<<""<<"";
                                    if (row ==1 && col ==3)

                                        cout <<" "<<board2[row--]<<""<<help2<<board1[col--]<<""<<"";

                    }


    return 0;
}

int DisplayMenu()   //function of main menu of the program
{
    char opt;     //char variable

            cout << "\nSelect One Option!";
            cout << "\n------------------";    //main menu of the program
            cout << "\n1|Game.";               // prints out all the options
            cout << "\n2|Boom.";               // that the user can edit
            cout << "\n3|Exit.";
            cout << "\nOption: ";
            cin >> opt;                       // check the option of the user

            switch (opt)            //switch case of the user input
            {
            case '1': minesweep();   // case 1: called the function minesweep
                break;               // break of case 1
            case '2': boardGenBOOM();   //case 2: called the function boardGenBOOM
                break;                  //break of case 2
            case '3': quit();           // case 3: called the function quit
                break;                  // break of case 3
            default: cout << "Error input, The program will exit.!!"<<endl; return 0;  //default: any other character will print out error
            }                                                                       //message and exit the program.....
            return 0;
}
Be a part of the DaniWeb community

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