EvilZone
Programming and Scripting => C - C++ => : Dijkstra May 03, 2013, 02:17:36 AM
-
Well I am in a pickle. I really need to figure this out by tomorrow, but I cannot for the life of my figure out why this is looping. I am no expert by far, more of a networking guy. Any help would be greatly appreciated.
http://pastebin.com/RQGjCgTd
-
can you explain the problem, so I can help ?
-
It is supposed to be able to solve any geometrical optics system using matrix algebra. But now, it just wants to infinitely loop itself.
When I compile it, all I get is:
This is a program that will perform matrix computations to output a system matrix, provided enough inputs are given. How many elements does this system have? Note that a thick lens counts as three elements: This is a program that will perform matrix computations to output a system matrix, provided enough inputs are given.
Thank you for your help
-
so at the very beginning you set
decision == 1
but you never change its value, hence never break from the while loop :)
-
At the end I cin a new decision though?
-
yep, you do that outside the while loop. your code right now is like:
case = true; // initial value
while(case)
{
} // end of while loop (case still equals the initial value)
case = false; // you'll never get here !
you should change the decision at the end of the while loop
-
Thank you Muhammad,
I moved the "}" down.
I am still getting loops with the code (index of 1, and index of prime).
Loop shows:
Do you wish to analyze another optical system? Enter '1' for 'yes' or '2' for 'no': This is a program that will perform matrix computations to output a system matrix, provided enough inputs are given. How many elements does this system have? Note that a thick lens counts as three elements: 0x7ffff961cb40
http://pastebin.com/VUBEgUPz (http://pastebin.com/VUBEgUPz)
-
I'm not sure why this is happening .. If you enter 2 at the end of the program it will break you out of the while loop.
Try adding this at line 409:
if (decision == 2 ) break;
-
Adding that fixes the planar refraction loop. The other options continue to loop for some reason. I know it has to be something simple, but it is not as obvious as I wish it was :(.
-
if(counter = 0) //this is for the first matrix calculation, so the element isn't multiplied by zero
{
It doesn't stop asking for new elements, because you assign 0 to the counter everytime in this if-statement.
Because of such hard to spot errors it is a better habit to make comparisons like this:
if(0 == counter) //this is for the first matrix calculation, so the element isn't multiplied by zero
{
If you had done the same mistake here, the compiler would have told you.
Btw your intendation is bad. You should do something about it. It is hard to see the structure of your code.
-
Thank you Deque and Muhammad, I finally got this working with your assistance.