+ 3
Second degree equation. Whats wrong ?
8 odpowiedzi
+ 5
try this actually the error is just of sign you used % ( i.e modulus ) rather than / ( i.e divide )
https://code.sololearn.com/cd2087AtzbG2/?ref=app
+ 5
it is used to raise a number to any power i.e 10^5 = pow(10,5)
+ 3
int D = b*b - 4*a*c;
// int --> double
double e = -b + sqrt (D);
double x = e / (2.0 * a); // was --> e % 2*a
double f = -b - sqrt (D); // b --> -b and minus between -b and sqrt
double xx = f / (2.0 * a); // was --> f % 2*a
cout << "First root: " << x;
cout << "\nSecond root: " << xx;
Test_1: 3x² + 5x + 2 = 0
3
5
2
First root: -0.666667
Second root: -1
Test_2: 3x² - 6x + 3 = 0
3
-6
3
First root: 1
Second root: 1
Test_3: x² + 2x + 5 = 0
1
2
5
First root: nan
Second root: nan
+ 2
Thabk you for helping me out
+ 2
double types hold numbers with fraction part like 3.14
int types hold only integer part of a number (and discard fraction part, if any).
+ 1
What's the difference between int and double ?
+ 1
And when u want to divise a lot of things they have to be in (). I understood. Thank you a lot!!! Sometimes i do some silly mistakes but i think its ok because i am not so used to it
0
One last question. Is there any way, for example, to show 1/4 instead of 0.25 ?