Why doesn't this code work properly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why doesn't this code work properly?

Thud program doesn't work as intended, what is the reason? https://code.sololearn.com/cZCHbfcOK8eN/?ref=app

22nd Oct 2022, 4:58 AM
Root
Root - avatar
13 Answers
+ 2
#include <iostream> #include <cmath> using namespace std; int main() { int a, b, c, x, y; cout << "a : "; cin >> a; cout << "b : "; cin >> b; cout << "c : "; cin >> c; cout << "x : "; cin >> x; y = a*pow(x,2) + b*x + c; cout << "y = " << y; return 0; }
23rd Oct 2022, 7:11 PM
Egor Rogashev
Egor Rogashev - avatar
+ 3
To obtain 14 where all <a> <b> <c> and <x> were 2, do ( x * 2 ) rather than ( x ^ 2 )
22nd Oct 2022, 7:01 PM
Ipang
+ 2
#include <iostream> using namespace std; int main() { int a, b, c, x, y; cout << "a : "; cin >> a; cout << "b : "; cin >> b; cout << "c : "; cin >> c; cout << "x : "; cin >> x; y = a*(x^2) + b*x + c; cout << "y = " << y; return 0; }
22nd Oct 2022, 5:43 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Pro grammer then provide more examples so people can figure out the formula. You only shared one case where everything was 2, who would've known?
23rd Oct 2022, 2:36 PM
Ipang
+ 1
Yaroslav Vernigora thanks you.
23rd Oct 2022, 5:23 AM
Root
Root - avatar
+ 1
Ipang right, but 2 was just an example
23rd Oct 2022, 5:23 AM
Root
Root - avatar
+ 1
#Include <math.h>
23rd Oct 2022, 5:53 AM
[Di]zzzZ
[Di]zzzZ - avatar
0
Yaroslav Vernigora what's the difference? 🧐
22nd Oct 2022, 5:50 AM
Root
Root - avatar
0
... b*x+c --->>> ... b*x+c; cout >> "y=" --->>> cout << "y="
22nd Oct 2022, 5:57 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Yaroslav Vernigora yeah, that's right, I fixed it, but it still returns the wrong answer. :( when I set all values as 2, it returns 6 instead of 14.
22nd Oct 2022, 6:26 AM
Root
Root - avatar
0
so the problem is with your formula. you will need to change it. this is already the field of mathematics. here I am not strong
22nd Oct 2022, 6:37 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Thank you guys, It was really helpful. Egor Rogashev [Di]zzzZ
24th Oct 2022, 6:11 PM
Root
Root - avatar
0
Yes, that's right, thank you. Ipang
24th Oct 2022, 6:13 PM
Root
Root - avatar