pjmes

05-15-2013, 03: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. :confused:

bob3584

05-15-2013, 03:08 PM

could you post it?

EDIT: Never-mind

chickentree

05-16-2013, 01:00 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. :confused:

First figure out what the Discriminant is:

http://www.algebra.com/algebra/homework/real-numbers/real-numbers.faq.question.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.

Other comments:

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

noSolutions – scientist says “your answer is irrational”

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