0

I am trying to output a 2D array with a border around it but for some odd reason I am not getting any output, just a blank space. I am pretty sure the problem is in the if statement but im not sure whats wrong.

#include <iostream>
#include "windows.h"
using namespace std;

//prototypes
void DisplayMap();
void SetBorder();

//global vars
const int H = 70;
const int W = 40;
char Map[H][W];

int main()
{
    //system("cls");
    DisplayMap();
    SetBorder();

    return 0;
}

void SetBorder(){
for(int i = 0; i < H; i++ ){
    for(int j = 0; j < W; j++){
        if(i == 0 || i == 69 || j == 0 || j == 39 ){ Map[i][j] = 'x';}
            // else Map[i][j] = ' ';
        }
    }
}


void DisplayMap(){
for(int i = 0; i < H; i++ ){
    for(int j = 0; j < W; j++){
            cout << Map[i][j];
        }
            cout << "\n";
    }


}

2 Answers 2

3
SetBorder();
DisplayMap();

Swap the function calls. You want to set the border characters first, then display the map.

Sign up to request clarification or add additional context in comments.

Comments

2

You need to fill the Map first and then to display it:

int main()
{
    //system("cls");
    SetBorder();
    DisplayMap();


    return 0;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.