#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 = ((bbb) + sqrt( b*b 4*a*c))/(2*a); answer2 = ((bbb)  sqrt( b*b 4*a*c))/(2*a); cout << answer1 << " is one solution " << answer2 << " is another"; return 0; }
Does this quadratic formula work?
Page 1 of 17 Replies  3019 Views  Last Post: 25 August 2007  02:51 AM
#1
Does this quadratic formula work?
Posted 24 August 2007  04:46 PM
Replies To: Does this quadratic formula work?
#2
Re: Does this quadratic formula work?
Posted 24 August 2007  05:09 PM
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
Re: Does this quadratic formula work?
Posted 24 August 2007  05:57 PM
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
Re: Does this quadratic formula work?
Posted 24 August 2007  06:22 PM
randomguy, on 24 Aug, 2007  04:46 PM, said:
#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 = ((bb + sqrt( b*b 4*a*c))/(2*a);
answer2 = ((bb  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.
#5
Re: Does this quadratic formula work?
Posted 24 August 2007  06:36 PM
PennyBoki, on 25 Aug, 2007  02:57 AM, said:
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
Re: Does this quadratic formula work?
Posted 24 August 2007  06:37 PM
#7
Re: Does this quadratic formula work?
Posted 25 August 2007  12:34 AM
PennyBoki, on 24 Aug, 2007  06:37 PM, said:
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
Re: Does this quadratic formula work?
Posted 25 August 2007  02:51 AM
musya, on 25 Aug, 2007  02:22 AM, said:
although, you can of course, have less than 2 points of intersection (the quadratic formula fails when the graph doesn't intersect with the Xaxis). 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
