I am just starting to make a matrix calculator and am frustrated to have run into problems so early. I am making a 3x3 Matrix calculator and am having problems entering values to the array, it runs fine as far as I can tell until "cin matrix[2][2];" when I get an error "Run-Time Check Failure #2 - Stack around the variable 'matrix' was corrupted." My guess would be I am entering outside the array and so it is undefined but I cannot see how I am, thanks for any help.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
double matrix[2][2];
for(int i=0;i<=2;i++)
{
for(int j=0;j<=2;j++)
{
cout<<"Enter value: ["<<i+1<<"]["<<j+1<<"] of your 3x3 vector.\n";
cin>>matrix[i][j];
}
}
cout<<matrix[1][2];
cin.get();
return 0;
}
the indexing of arrays in c++(and in fact in many programming languages)begins from 0.But when you specify the size you don't count from 0.So it should be-
double matrix[3][3];
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments