ok, im writing a code that will triangulize (sp?) a 3 system, 3 variable equation. however, upon inputing the final variable in the array (the sum in the 3rd equation) it says the program crashed and i will all unsaved data in it, blah blah blah. it happened here at school on windows 95, and at home on XP. here is the code, it compiles fine for me, but if you dont use dev-cpp i think you might have to change the system pause to getch or whatever you use. i also apologise for the lack of comments
Code:#include <iostream> #include <string> void input(); void calculate(); void output(); int data[4][5]; int main() { input(); calculate(); output(); system("Pause"); return 0; } void input() { for (int a = 0; a < 3; a++) { for (int b = 0; b < 4; b++) { switch (b) { case 0: cout << "\nEnter the X in the " << a + 1 << " equation.\n"; break; case 1: cout << "\nEnter the Y in the " << a + 1 << " equation.\n"; break; case 2: cout << "\nEnter the Z in the " << a + 1 << " equation.\n"; break; case 3: cout << "\nEnter the sum of the " << a + 1 << " equation.\n"; break; default: cout <<"\n\nERROR: Line 39\n\n"; } cin >> data[a][b]; } } } void calculate() { int temp = data[0][0] / data[1][0]; for (int a = 0; a < 4; a++) { data[1][a] *= temp; data[1][a] = data[0][a] - data[1][a]; } temp = data[0][0] / data[2][0]; for (int a = 0; a < 4; a++) { data[2][a] *= temp; data[2][a] = data[0][a] - data[2][a]; } temp = data[1][1] / data[2][1]; for (int a = 0; a < 4; a++) { data[2][a] *= temp; data[2][a] = data[1][a] - data[2][a]; } temp = data[2][2] / data[2][3]; data[1][2] *= temp; data[0][2] *= temp; temp = (data[1][3] - data[1][2]) / data[1][1]; data[0][1] *= temp; temp = (data[0][3] - (data[0][1] + data[0][2])) / data[0][0]; data[0][0] *= temp; } void output() { for (int a = 0; a < 3; a++) { for (int b = 0; b < 4; b++) cout << data[a][b] << " "; cout << "\n"; } }