7 Replies - 2965 Views - Last Post: 25 August 2007 - 02:51 AM Rate Topic: -----

#1 randomguy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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)
{
	double a,b,c,answer1,answer2;
	
	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);
	
	cout << answer1 << "  is one solution  " << answer2 
					 << "  is another";
	
	 return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Does this quadratic formula work?

#2 mattman059  Icon User is offline

  • Epic Awesomeness
  • member icon

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

Re: Does this quadratic formula work?

Posted 24 August 2007 - 05:09 PM

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





apparently it it wanted the last b to be a smiley :P

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

Was This Post Helpful? 0
  • +
  • -

#3 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • 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.
Posted Image
Was This Post Helpful? 0
  • +
  • -

#4 musya  Icon User is offline

  • D.I.C Lover
  • member icon

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

Re: Does this quadratic formula work?

Posted 24 August 2007 - 06:22 PM

View Postrandomguy, on 24 Aug, 2007 - 04:46 PM, said:

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

int main(int)
{
double a,b,c,answer1,answer2;

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);

cout << answer1 << " is one solution " << answer2
<< " is another";

return 0;
}


This is incorrect, becuase you could have more than 2 zero's, not every function has 2 zero's.
Was This Post Helpful? 0
  • +
  • -

#5 1lacca  Icon User is offline

  • code.rascal
  • member icon

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

Re: Does this quadratic formula work?

Posted 24 August 2007 - 06:36 PM

View PostPennyBoki, 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.
Posted Image

I think we should have a shortcut to this picture!
Was This Post Helpful? 0
  • +
  • -

#6 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Does this quadratic formula work?

Posted 24 August 2007 - 06:37 PM

View Postmusya, 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?
Was This Post Helpful? 0
  • +
  • -

#7 musya  Icon User is offline

  • D.I.C Lover
  • member icon

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

Re: Does this quadratic formula work?

Posted 25 August 2007 - 12:34 AM

View PostPennyBoki, on 24 Aug, 2007 - 06:37 PM, said:

View Postmusya, 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

Was This Post Helpful? 0
  • +
  • -

#8 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 856
  • View blog
  • Posts: 2,339
  • Joined: 20-August 07

Re: Does this quadratic formula work?

Posted 25 August 2007 - 02:51 AM

View Postmusya, 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1