- #1
Vorde
- 788
- 0
Hello all,
I'm not really a programmer at all, but I learned c++ for a while so I can do basic stuff. Having just finished my linear algebra class I suddenly had an urge to write myself a simple matrix solver. I knew it wouldn't be easy (especially because of my lack of skill) but I was curious.
It was going great until I noticed that large matrices would crash the program. It's very weird. If the number of entries in my matrix array is less than 10 then everything works fine, but the second it hits 10 it stops working. I get the following message:
I was hoping someone could help me figure out why in gods name this is happening. I apologize in advance for the messiness of my code, I haven't yet made it nice (I was going to once I got the matrix entry down), but I put in a couple of notes to try and help.
Thank you very much :)
Edit: Something I should add: it doesn't crash when I made the size > 10 entries, it crashes when I enter the value for the 10th entry.
I'm not really a programmer at all, but I learned c++ for a while so I can do basic stuff. Having just finished my linear algebra class I suddenly had an urge to write myself a simple matrix solver. I knew it wouldn't be easy (especially because of my lack of skill) but I was curious.
It was going great until I noticed that large matrices would crash the program. It's very weird. If the number of entries in my matrix array is less than 10 then everything works fine, but the second it hits 10 it stops working. I get the following message:
Windows has triggered a breakpoint in Matrix.exe.
This may be due to a corruption of the heap, which indicates a bug in Matrix.exe or any of the DLLs it has loaded.
I was hoping someone could help me figure out why in gods name this is happening. I apologize in advance for the messiness of my code, I haven't yet made it nice (I was going to once I got the matrix entry down), but I put in a couple of notes to try and help.
Thank you very much :)
Edit: Something I should add: it doesn't crash when I made the size > 10 entries, it crashes when I enter the value for the 10th entry.
Code:
// Matrix.cpp : main project file.
#include "stdafx.h"
#include <iostream>
int main()
{
using namespace std;
// definition of array values
struct Entry
{
long double Value;
int mVal;
int nVal;
bool pivot;
};
// beginning of program
int mSize;
int nSize;
int tSize;
Entry *toSize = new Entry[tSize]; // creating array
cout << "Height of Matrix (M-Val):" << endl;
cin >> mSize;
cout << "Width of Matrix (N-Val):" << endl;
cin >> nSize;
tSize = (nSize * mSize);
int B;
int Num = 1;
int modN = 1;
int modM = 1;
// entering values
while (B < tSize)
{
long double value;
cout << "What do you want entry " << "(" << modM << "," << modN << ")" << " to be?" << endl;
cin >> value;
toSize[B].Value = value;
if (modN < nSize)
{
toSize[B].nVal = modN;
toSize[B].mVal = modM;
}
else
{
toSize[B].nVal = modN;
modN = 0;
toSize[B].mVal = modM;
modM ++;
}
B ++;
Num ++;
modN ++;
}
int T;
cout << "\n \n" << endl;
// printing values and placements
while (T < tSize)
{
cout << "Value is:" << toSize[T].Value << endl;
cout << "M-Placement is: " << toSize[T].mVal << endl;
cout << "N-Placement is: " << toSize[T].nVal << endl;
cout << "\n" << endl;
T++;
}
// so it doesn't close immediately
cin.clear();
cin.ignore(255, '\n');
cin.get();
}