I am trying to write a program to add large numbers with stacks. However, I do not know how to get each digit on to a stack individually.
This is what I mean:
For example, take the input 3784. How do I get the 3, 7, 8, and 4 as separate numbers so I can push them on to the stack starting with the first position.
The stack needs to look like this:
I am trying to implement an addingLargeNumbers() function which looks like this:
addingLargeNumbers() read the numerals of the first number and store the numbers corresponding to them on the stack; read the numerals of the second number and store the numbers corresponding to them on another stack; result = 0; while(!stack1.empty() || !stack1.empty()) //while at least one stack is not empty int x = stack1.pop() + stack2.pop(); result.push(x); //pop a number from each nonempty stack and add them to result; push the unit part on the result stack; store carry in result; push carry on the result stack if it is not zero; pop numbers from the result stack and display them;
Not sure if that helps but...