Miscellaneous > Programming & Networking
A programming challenge all up in your face.
TheQuirk:
I wrote a bunch of thing, but after I looked at the previous posts, it turned out that I didn't need to write them! So, useless post. Looking at code now.
mobrien_12:
--- Quote from: worker201 ---Any suggestions?
--- End quote ---
The logic seems good... the only problem seems to be that in the shuffle you somehow broke the discriminant calculations. Actually, I broke them too when I was making the changes I posted above, and it took a while to figure it out then, so I know it's really easy to break them when shuffling ... In my case I lost the slope= line and everything went to hell :)
It's probably something really simple to fix.
I put the troubleshooting frprintf statements that I was using earlier into this latest version and you can see the difference for the basic test case
--- Code: ---
0
0
10
10
2
5 5 1
20 20 2
--- End code ---
--- Quote from: new version ---
terms a, b c discrim 1.000000 -0.000000 0.000000 0.000000
circle # 1 does not intersect the line
terms a, b c discrim 1.000000 -0.000000 0.000000 0.000000
circle # 2 does not intersect the line
--- End quote ---
--- Quote from: old version edited by mobrien ---
terms a, b c discrim 2.000000 -20.000000 49.000000 8.000000
terms a, b c discrim 2.000000 -80.000000 796.000000 32.000000
circle # 2 does not intersect the line
--- End quote ---
worker201:
I could probably fix it, by adding the contents of the function back into main. I just figured it was stupid to write the exact same code twice. That's what functions are for, right? I think the program as it stands right now looks terrible, and requires too much maintenance. All those ifs and elses, with the attendant braces and indents, are difficult to keep up with. Then again, it would be even more of a pain in the ass to keep passing array variables back and forth through blackbox functions. What's a boy to do?
I was reading the criticisms of C on wikipedia. Too easy to get something wrong, and too hard to get something right. I think that's somewhat accurate.
mobrien_12:
But, as you wrote it, the function has nothing to do with the discriminant calculation. It calculates path length. The discriminant is used first to decide if the function should be called or not. The discriminant calculation is what is broken.
I'm pretty sure this is a little bug and has nothing to do with your decision to split repeated code off into a function, which I totally agree is what is the issue... nor is it particularly more difficlult in C in this case I think...even Octave is a pain in the ass when you have a hiccup. This is just a little glitch you picked up when shuffling your code around. :)
TheQuirk:
Suggestion: Why not make a function where you pick which variable is independent, and which is dependent? That way you could have something along the lines of the following.
--- Code: ---if (x1 == x2) {
happyfunction(y1, y2, x1, x1);
}
else {
happyfunction(x1, x2, y1, y2);
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version