Write your question here.
Hello my program takes an input turns it into a 2d array then reverses it. When I try to output my array it outputs 3 negative numbers then crashes.
Error:
A buffer overrun has occurred in 2d Array Reverse.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.
// 2d Array Reverse.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int board[2][3];
int width=3;
int height=4;
cout<< "Enter your First Row First Number"<<endl;
cin>> board[0][1];
cout<< "Enter your First Row Second Number"<<endl;
cin>> board[0][2];
cout<< "Enter your First Row Third Number"<<endl;
cin>> board[0][3];
cout<< "Enter your Second Row First Number"<<endl;
cin>> board[1][1];
cout<< "Enter your Second Row Second Number"<<endl;
cin>> board[1][2];
cout<< "Enter your Second Row Third Number"<<endl;
cin>> board[1][3];
cout<< "Enter your Third Row First Number"<<endl;
cin>> board[2][1];
cout<< "Enter your Third Row Second Number"<<endl;
cin>> board[2][2];
cout<< "Enter your Third Row Third Number"<<endl;
cin>> board[2][3];
cout<< "Enter your Fourth Row 1st Number"<<endl;
cin>> board[3][1];
cout<< "Enter your Fourth Row 3rd Number"<<endl;
cin>> board[3][2];
cout<< "Enter your Fourth Row 4th Number"<<endl;
cin>> board[3][3];
for(int i = 0; i<width; i++)
{
for(int j=0; j<height; j++)
{
cout<< board[i][j] << " "<<endl;
}
}
return 0;
}
You have your array dimensions mixed up. You initialize an array to by 3x4, but you try to enter numbers into a 4x3 array. The for loop is correct for a 3x4 array.
it still gives me
A buffer overrun has occurred in 2d Array Reverse.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.
(I updated the code)