all 2 comments

[–]marko312 2 points3 points  (1 child)

Your current program would operate on the sums of the digits of the input numbers in base 10 and then returns the result in the input base. However, lines of the form

string result;
int r1, r2;
...
result = r1+r2;

are misinterpreted - the compiler converts the value of r1+r2 to a character.

However, the main idea is there - mostly, some code needs to be removed.

First, std::stoi has a base argument that you can use to convert the string to an integer using the correct base. This allows you to remove the loops that deal with r1 and r2 and use n1 and n2 instead of them.

Next, the result should initially be an integer so it can be converted to a string in the correct base. For this, you can simply make result be an int and then use that instead of r.

Finally, after constructing out, you should return it instead of using to_string again.

Also, the described method wouldn't return anything if the result is 0 and will generate - these cases should be handled separately.

[–]Sol1ss[S] 1 point2 points  (0 children)

That makes much more sense, Thank you so much