Maybe the program crashes when the first 3 for loops write out of bounds of rightisosceles. The sizes are [100][4][10] but you write form 0 to 100 in each place. Note that from 0 to 100 there are 101 values while you only have 100 so even the first loop isn't right. You should use < in your for loops.
Another problem is with your other for loops. n+5 does not modify n, so the loop would be infinite. The right way would be n=n+5 or n+=5.
Thank you hamsterman. I modified the code but it is still having a problem... it's giving me all 0s for the values with the exception of 2 values and then it crashes and the operating system shuts it down. I am using code::blocks with Win XP. Here is the modified code:
# include <iostream>
#include <fstream>
using namespace std;
float rightisosceles [100][4][10];
float n, n1;
float ydisplacement2 = 0.0;
float righttrianglebase = 1.0;
float righttriangleheight = 1.2;
int v = 1, isoscelescounter = 1;
int p, hh, oo, pp;
int main()
{
for (hh = 0; hh <100; hh++) {
for (oo = 0; oo <4; oo++) { for (pp = 0; pp <10; pp++)
{
rightisosceles [hh][oo][pp] = 0.0;
}
}
}
for (n = 3.0 ; n <=70; n = n + 5) { // positioning particles
for (n1 = 4.0 ; n1 <= 39; n1 = n1 + 5) {
ok. I increased the size of rightisosceles [150][4][10]. The program is not crashing anymore but the x,y values are all 0s. This is the modified program:
# include <iostream>
#include <fstream>
using namespace std;
float rightisosceles [150][4][10];
float n, n1;
float ydisplacement2 = 0.0;
float righttrianglebase = 1.0;
float righttriangleheight = 1.2;
int v = 1, isoscelescounter = 1;
int p, hh, oo, pp;
int main()
{
for (hh = 0; hh <150; hh++) {
for (oo = 0; oo <4; oo++) { for (pp = 0; pp <10; pp++)
{
rightisosceles [hh][oo][pp] = 0.0;
}
}
}
for (n = 3.0 ; n <=70; n = n + 5) { // positioning particles
for (n1 = 4.0 ; n1 <= 39; n1 = n1 + 5) {
Thank you hamsterman but again all values I have are 0s. I tried printing the n's n1's and v's and they print just fine but when I try to assign values to the array (any array) they keep on giving me 0s.Something is not working in this code, or could it be a software glitch..because it totally does not make any sense.
Did you misunderstand my last post? Look, let's take the first cycle, where v = 0.
First you set rightisosceles [0][0][1] to n and etc.
Then you increment v so that it is 1.
And finally you print rightisosceles [1][0][1]. You filled all the array with 0s, so of course, the next element will be 0.
Now if you do incrementing after printing, this problem will not occur.