pjmes
Junior Member

Status: Offline
Posts: 1
Join Date: May 2013
Quadratic Formulation Help - 05-15-2013, 04:07 PM

Hello, I am trying to make a program where the user puts in the number they chose for each a, b, c coefficients. Then from there it computes and the professor says the answer. How do I make the numbers change each letter on the board to that number when entered? Also I am getting lost in the computing the answer, please help with what i need further to get this to compute correctly. It just keeps saying 0.
Attached Files
 Quadratic Formula.a2w (1.46 MB, 7 views)

 bob3584 Senior Member   Status: Offline Posts: 180 Join Date: Jan 2013 Location: In a Cardboard Box. 05-15-2013, 04:08 PM could you post it? EDIT: Never-mind My avatar will always be a preview of what I am currently working on.
chickentree
Super Moderator

Status: Offline
Posts: 212
Join Date: Dec 2012
Location: Frosno, Ca
05-16-2013, 02:00 PM

Quote:
 Originally Posted by pjmes Hello, I am trying to make a program where the user puts in the number they chose for each a, b, c coefficients. Then from there it computes and the professor says the answer. How do I make the numbers change each letter on the board to that number when entered? Also I am getting lost in the computing the answer, please help with what i need further to get this to compute correctly. It just keeps saying 0.
First figure out what the Discriminant is:
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^2-4ac. Then use the return value and nested if statements to determine your answer(s):
• If <0 there are no real answers to the equation.
• If = 0 There is one solution (or two but both are the same number) the correct answer depends on your geek level.
• If >0 There are two real answers.
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^2-4ac” 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 (-b-SqrRt(d))/(2a).
So solutionA would call
• oneSolution – scientist says “There is one answer and it is “ joined with -b/(2a) as a string
• twoSolutions – well you should be able to get there from here.
Hope this helps,
Mark

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge