I have the following code to sum the raws of an array.
Basically I have 4 raw and xx col and I want to sum the raw in that order:
raw 2 and raw 3
raw 2 and raw 3 and raw 4
raw 1 and raw 3
raw 1 and raw 3 and raw 4
The loops work except that it keeps accumulating. I am sure it's because I need to reinitialize my array within the loop, I tried at line 37, but it won't work.
I'm not sure what you want to obtain, but for the start let me tell you what you have to fix:
1. You can get rid off the std:: scope by making it global with this instruction usingnamespace std;
After this, you don't have to type std::cout/std::cin.get() etc, just cout, cin.get() etc. It gives you a ,,better" picture of the code. Be advised, at some points it might get into conflict with what you write.
2. You don't have reinitialize the dens4d variables. Every global variable is always initialized with 0. In the case you would have declared your variables inside the function, everything would have collapsed, because in your code, you firstly make the sum, then initialize, which results in a big error.
3. If you set after every second while loop dj=3, what do you think it will happen? The second while will always meet it's condition and will repeat forever, despite you increment it. You must eliminate the dj=3 instruction, and the code will work.
4. For the sake of beauty, terminate those 2 processes with this function. variable.close(); where variable is tryy and dens