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
13 Respuestas
+ 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;
}
+ 3
To obtain 14 where all <a> <b> <c> and <x> were 2, do ( x * 2 ) rather than ( x ^ 2 )
+ 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;
}
+ 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?
+ 1
Yaroslav Vernigora thanks you.
+ 1
Ipang right, but 2 was just an example
+ 1
#Include <math.h>
0
Yaroslav Vernigora what's the difference? 🧐
0
... b*x+c --->>> ... b*x+c;
cout >> "y=" --->>> cout << "y="
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.
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
0
Thank you guys, It was really helpful.
Egor Rogashev
[Di]zzzZ
0
Yes, that's right, thank you. Ipang