0

problem with code

in the attached code, the problem is not evident, pls help me correct this code https://code.sololearn.com/ckSf18BK2IlE/?ref=app

4th Dec 2020, 5:38 PM
Eresh Mittal
Eresh Mittal - avatar
2 Respuestas
+ 3
There are multiple issues: 1. The variable 'v' is not initialized, you should assign it an initial value (0): int v = 0; 2. std::pow() returns a floating type value, but it looks like you are relying on integer division in your first loop condition. Casting the result to an integral value would solve this, e.g. ...; n / ( int ) pow( 10, i ); ... 3. You need to start writing digits into the array starting at ( u - 1 ), not 'u'. Either you change the index you access the array with, or the loop initialization and value calculation, e.g. digits[ u - 1 ] = first_digit;
4th Dec 2020, 8:13 PM
Shadow
Shadow - avatar
0
thank you very much, i did what u explained in the first two points and it worked, i could not understand your third point, anyway i dont understand how initializing v was important?
5th Dec 2020, 4:52 PM
Eresh Mittal
Eresh Mittal - avatar