Can someone analyze what's wrong? | Sololearn: Learn to code for FREE!
+ 1

Can someone analyze what's wrong?

It should calculate L, but shows -0 int main() { int i, k, j; double L = 0, sum; cout << "Enter k = "; cin >> k; for (j = 1; j <= k; j++) if (j != 2) { sum = 1; for (i = k; i <= 12; i++) sum += sqrt(i + 5) / (i - 1); L *= (j - 5) /( j - 2) + sum; } cout << "Multiplication: " << L; cin.get(); cin.get(); return 0; }

11th Dec 2022, 9:41 PM
Tripleks Cидик
Tripleks Cидик - avatar
4 ответов
+ 2
Tripleks Cидик From what it looks like, because you set L = 0 then the output will always be 0. 0 *= 10 = 0 0 *= 20 = 0 https://code.sololearn.com/cg45W0arZIBk/?ref=app Try running code "discuss quest". Using cout to follow the path can be really helpful solving errors. After you try it, set double L, sum; giving L no value. Then test again. It won't solve all the errors but you will notice a difference. https://code.sololearn.com/ciSUvA8PGvwf/?ref=app
12th Dec 2022, 1:43 AM
Scott D
Scott D - avatar
+ 1
https://code.sololearn.com/cd30j0LEZ6Nl/?ref=app I think this is the solution, thank you
12th Dec 2022, 3:17 AM
Tripleks Cидик
Tripleks Cидик - avatar
0
Tripleks Cидик If my answer helped a little I'm happy. But although my c++ skills are getting a little better I'm not very good with math, so I have no idea if this truly works or not. I'm not sure exactly what your code is meant to accomplish. Sometimes it's good to try to describe the specific task you want to accomplish and then others can be more helpful, there are some very good and knowledgable people here. And you didn't have to credit me in your code, you wrote it, I only noticed one possible little error.
12th Dec 2022, 4:08 AM
Scott D
Scott D - avatar
0
It was a nested loop with multiplication and sum I'm really thankful for your advice
12th Dec 2022, 4:23 AM
Tripleks Cидик
Tripleks Cидик - avatar