# Does this quadratic formula work?

Page 1 of 1

## 7 Replies - 3132 Views - Last Post: 25 August 2007 - 02:51 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=32192&amp;s=d6f1bccab40c7b4a24190040a3a287e5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 randomguy

Reputation: 0
• Posts: 1
• Joined: 24-August 07

# Does this quadratic formula work?

Posted 24 August 2007 - 04:46 PM

```#include <iostream.h>
#include <math.h>

int main(int)
{

cout << "Enter a:   ";
cin >> a;

cout << "\nEnter b:   ";
cin >> b;

cout << "\nEnter c:   \n";
cin >> c;

answer1 = ((b-b-b) + sqrt( b*b -4*a*c))/(2*a);
answer2 = ((b-b-b) - sqrt( b*b -4*a*c))/(2*a);

<< "  is another";

return 0;
}
```

Is This A Good Question/Topic? 0

## Replies To: Does this quadratic formula work?

### #2 mattman059

• Epic Awesomeness

Reputation: 15
• Posts: 538
• Joined: 23-October 06

## Re: Does this quadratic formula work?

Posted 24 August 2007 - 05:09 PM

instead of saying (b-b- you could instead say 0 - b or -b i believe.

apparently it it wanted the last b to be a smiley

This post has been edited by mattman059: 24 August 2007 - 05:09 PM

### #3 PennyBoki

• system("revolution");

Reputation: 53
• Posts: 2,335
• Joined: 11-December 06

## Re: Does this quadratic formula work?

Posted 24 August 2007 - 05:57 PM

HI randomguy welcome aboards. Your code compiles just fine in MVC++ but it doesn't compile in devc++ because of the standards thing, the use of <iostream> instead of <iostream.h>...
So your code works. And next time please use code tags for the code.
All you have to do is select the code and click on the # button on the menu.

### #4 musya

• D.I.C Lover

Reputation: 11
• Posts: 1,012
• Joined: 25-April 07

## Re: Does this quadratic formula work?

Posted 24 August 2007 - 06:22 PM

randomguy, on 24 Aug, 2007 - 04:46 PM, said:

#include <iostream.h>
#include <math.h>

int main(int)
{

cout << "Enter a: ";
cin >> a;

cout << "\nEnter b: ";
cin >> b;

cout << "\nEnter c: \n";
cin >> c;

answer1 = ((b-b- + sqrt( b*b -4*a*c))/(2*a);
answer2 = ((b-b- - sqrt( b*b -4*a*c))/(2*a);

<< " is another";

return 0;
}

This is incorrect, becuase you could have more than 2 zero's, not every function has 2 zero's.

### #5 1lacca

• code.rascal

Reputation: 44
• Posts: 3,822
• Joined: 11-August 05

## Re: Does this quadratic formula work?

Posted 24 August 2007 - 06:36 PM

PennyBoki, on 25 Aug, 2007 - 02:57 AM, said:

HI randomguy welcome aboards. Your code compiles just fine in MVC++ but it doesn't compile in devc++ because of the standards thing, the use of <iostream> instead of <iostream.h>...
So your code works. And next time please use code tags for the code.
All you have to do is select the code and click on the # button on the menu.

I think we should have a shortcut to this picture!

### #6 PennyBoki

• system("revolution");

Reputation: 53
• Posts: 2,335
• Joined: 11-December 06

## Re: Does this quadratic formula work?

Posted 24 August 2007 - 06:37 PM

musya, on 24 Aug, 2007 - 06:22 PM, said:

This is incorrect, becuase you could have more than 2 zero's, not every function has 2 zero's.

what do you mean two zeros?

### #7 musya

• D.I.C Lover

Reputation: 11
• Posts: 1,012
• Joined: 25-April 07

## Re: Does this quadratic formula work?

Posted 25 August 2007 - 12:34 AM

PennyBoki, on 24 Aug, 2007 - 06:37 PM, said:

musya, on 24 Aug, 2007 - 06:22 PM, said:

This is incorrect, becuase you could have more than 2 zero's, not every function has 2 zero's.

what do you mean two zeros?

Ive had a great example but i forgot it sorry, but for instance you might end up taking the square root of a squar root. If i dont have an example for you you'll think im stupid, sorry i forgot it, i guess forget it. But there is an instance where that might not work. Another thing would be if one or both of the answers elaborated to an imaginary number. this isnt as bad as doing integration or differentiation in programming. I believe you'd have to use Newtons method of approximation for that though, cant imagine a way to integrate the way humans do in programming.

This post has been edited by musya: 25 August 2007 - 12:37 AM

### #8 Bench

• D.I.C Lover

Reputation: 859
• Posts: 2,343
• Joined: 20-August 07

## Re: Does this quadratic formula work?

Posted 25 August 2007 - 02:51 AM

musya, on 25 Aug, 2007 - 02:22 AM, said:

This is incorrect, becuase you could have more than 2 zero's
No, you cannot have more than 2 points of intersect across the X-axis (Which is what I assume you mean by 'zeroes') .. Have a look at wikipedia's entry for more information http://en.wikipedia....dratic_equation

although, you can of course, have less than 2 points of intersection (the quadratic formula fails when the graph doesn't intersect with the X-axis). It would be a good idea to add a check for negative numbers before passing (b*b -4*a*c) to the sqrt function

This post has been edited by Bench: 25 August 2007 - 02:57 AM