
Quadratic Formulation Help 
Super Moderator
Status: Offline
Posts: 249
Join Date: Dec 2012
Location: Frosno, Ca

05162013, 01:00 PM
Quote:
http://www.algebra.com/algebra/homew...ion.48581.html For instance describes the what and why. I would have your discriminant function return a number rather than a Boolean. Specifically, I would have it return b^24ac. Then use the return value and nested if statements to determine your answer(s):
In discriminant you pass in a,b,&c but then immediately over write them with world.a, world.b and world.c respectively (which is what was passed in anyway.) Passing in these variables is a better practice so just delete the 3 assignment statements. Next use them to calculate the discriminant and return the value. In solutionA: You are calling solutionOne and then printing x, which is passed in from world.x and initialized to 0. In solutionOne: Right now discriminant always returns true so the first part of the first if is always run. In the second if statement you are not calculating x you are comparing the results of the quadratic equation to whatever x is to see if they are equal (==). In your case x is 0, as that is the default value set for world.x. After this comparison, no mater what the outcome, you are doing nothing and returning true. It is my guess that what you want is something like In solutionA set d = discriminant (changing the discriminant function as described above.) Then compare the discriminant to 0 as described above and call a method depending on the result for instance if d<0 then call noSolutions. For the other two cases you need to complete the quadratic formula. But you have already figured out “b^24ac” and set d to its value so use it. Along with b and a to get your answer. If there is only one answer it is b/(2a) otherwise it is (b+SqrRt(d))/(2a) and (bSqrRt(d))/(2a). So solutionA would call
Mark 



Thread Tools  
Display Modes  

