|
||
|
|
#1 (permalink) |
|
Master of the Internet
|
I know this is simple, but I am teaching myself and i am trying to figure out why I am getting the wrong answer.
I think it is probably my order of operations. Code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout<<"The Quadratic Formula is represented as..."<<endl;
cout<<"-b+sqrt(b^2-4ac)/2a \n& \n-b-sqrt(b^2-4ac)/2a"<<endl;
cout<<"Enter the value of your polynomials."<<endl;
double a, b, c, x1, x2, q;
cout<<"A=";
cin>>a;
cout<<"\nB=";
cin>>b;
cout<<"\nC=";
cin>>c;
x1 = (-b+sqrt((b*b)-4*a*c))/2*a;
cout<<"X="<<x1;
cin>>q;
return 0;
}
|
|
|
|
|
|
#2 (permalink) |
|
Forum Expert
|
I'd try to put a parentheses there, since the numerator part of the expression "(-b+sqrt((b*b)-4*a*c))" is divided by 2, then multiplied by A.
Code:
x1 = (-b+sqrt((b*b)-4*a*c))/(2*a);
__________________
Angels are falling the very last time, down they're burning in hate and decline, unfaithful and violent we're breaking the spell, we're god, we're scissor, in heaven and hell! |
|
|
|
|
|
#4 (permalink) |
|
Forum Expert
|
Those numbers sounds like an error to me, because they will give you a negative argument to the sqrt, which will result in mathematical error.
Code:
3^2 - 4 * 1 * 4 = 9 - 16 = -7
__________________
Angels are falling the very last time, down they're burning in hate and decline, unfaithful and violent we're breaking the spell, we're god, we're scissor, in heaven and hell! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|