How can I go about padding an array of a certain size so that it will align with another one?

For example I have an addition problem I am working out and cannot find the solution to.
When my program prints it out it will look like this:

1234567 should be ----> 1234567
1234 should be ----> 0001234
------- -------
2468342 should be ----> 1235801

The firs numbers add correctly and then afterwards they are junk numbers. How could I pad the second array which contains the 1234 to shift to the right. I believe it may have something to do with the #include<iomanip> library. Also the size of the arrays are not static they are chosen by the user at the beginning of the program, so the I think the padding will have to be dynamic.

I don't want the code but any suggestions or nudges in the right direction would be helpful.

You are using int[] arrays...

Since you have requested hints and not code, i'll write out a suggested process in pseudocode:

1. using a loop, initialize all array elements to zero. Do this for every int[] array you are using.

2. populate your arrays from 'right-to-left' as opposed to the traditional left-to-right method. (this will probably involve changing loop conditions to start at then end of the array and decrement backwards towards the [0] element)

3. any elements that do not get populated will hold a zero value :)

Edited 6 Years Ago by Clinton Portis: n/a

Thanks, now that I have had a chance to step away from the console that makes sense

Also consider using string/list<int> instead of ints[]. That way its easier to change the whole array if you need to.

another afterthought,

you could populate your int arrays normally, and then perform some type of 'reverse' operation on them whenever you are ready to use them.

This article has been dead for over six months. Start a new discussion instead.