[Solved] Debugging help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

[Solved] Debugging help

Hey, I'm writing a C++ program to solve the Daily Teaser asked by SoloLearn but seem to have hit a dead end. I have eradicated all compile time errors but the output is very absurd. Please help. https://code.sololearn.com/cCmtM2RAo896/?ref=app

27th Feb 2019, 6:57 AM
Kainatic [Mostly Inactive Now]
Kainatic [Mostly Inactive Now] - avatar
9 Answers
+ 5
Bad_Bit Works good. Solves the problem. But the thing is I was trying to make the code dynamic. For example, Input: 10, 3, 2 Logic: 10^2 + 3^2 + 2^2 = 113 Output: 113 So the code should be able to read multiple digits and multiple numbers. Also, sstream::stringstream is used to convert string to integer. Refer: https://www.geeksforgeeks.org/converting-strings-numbers-cc/amp/
27th Feb 2019, 8:25 AM
Kainatic [Mostly Inactive Now]
Kainatic [Mostly Inactive Now] - avatar
+ 8
It's very complex Temp is not initialised And you are indexing it with [0] So make temp a string of length equal to how many digits you want in number For 1 digit number temp = "0" ; //put anything
27th Feb 2019, 7:20 AM
good_bits
good_bits - avatar
+ 8
Also your loop will not calculate the second number it skips it
27th Feb 2019, 7:21 AM
good_bits
good_bits - avatar
+ 8
Ok
27th Feb 2019, 7:50 AM
good_bits
good_bits - avatar
27th Feb 2019, 8:17 AM
good_bits
good_bits - avatar
+ 8
Updated please don't use spaces use "," for separation https://code.sololearn.com/cF592tOQmpLZ/?ref=app
27th Feb 2019, 9:32 AM
good_bits
good_bits - avatar
+ 7
Ok I made it for two numbers and single digits I will update it
27th Feb 2019, 8:31 AM
good_bits
good_bits - avatar
+ 6
Bad_Bit Thank you.
27th Feb 2019, 7:58 AM
Kainatic [Mostly Inactive Now]
Kainatic [Mostly Inactive Now] - avatar
+ 4
Bad_Bit If you don't mind, could you please debug the code. I am not sure how to go further.
27th Feb 2019, 7:38 AM
Kainatic [Mostly Inactive Now]
Kainatic [Mostly Inactive Now] - avatar