Second degree equation. Whats wrong ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Second degree equation. Whats wrong ?

Pls help https://code.sololearn.com/c4Sz345akZM8/?ref=app

19th Nov 2018, 12:08 PM
Tasos T
Tasos T - avatar
8 Answers
+ 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
19th Nov 2018, 12:24 PM
Madhav
Madhav - avatar
+ 5
it is used to raise a number to any power i.e 10^5 = pow(10,5)
19th Nov 2018, 12:31 PM
Madhav
Madhav - avatar
+ 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
19th Nov 2018, 1:01 PM
Babak
Babak - avatar
+ 2
Thabk you for helping me out
19th Nov 2018, 12:32 PM
Tasos T
Tasos T - avatar
+ 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).
19th Nov 2018, 2:45 PM
Babak
Babak - avatar
+ 1
What's the difference between int and double ?
19th Nov 2018, 2:21 PM
Tasos T
Tasos T - avatar
+ 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
19th Nov 2018, 4:33 PM
Tasos T
Tasos T - avatar
0
One last question. Is there any way, for example, to show 1/4 instead of 0.25 ?
19th Nov 2018, 4:42 PM
Tasos T
Tasos T - avatar