Reputation: 755
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";
}
}
Upvotes: 0
Views: 203
Reputation: 22157
You need to fill the Map
first and then to display it:
int main()
{
//system("cls");
SetBorder();
DisplayMap();
return 0;
}
Upvotes: 2
Reputation: 361585
SetBorder();
DisplayMap();
Swap the function calls. You want to set the border characters first, then display the map.
Upvotes: 3