I'm working on a bonus project for my C++ class. The original problem was to add two large numbers given by the professor, or more specifically, write a program that would add these two numbers. After a while I got it working, relitively easy bit of code with some pointers from a classmate.
This bonus project will help my grade, but aas the name implies, is not required. So I'm modifying my code to do subtraction, multiplication and division of these numbers. The problem is that I'm subtracting in columns but don't know how to add 10 to the current number on the stack and then subtract 1 from the next number since I'm not yeat dealing with the number that has yet to come.
Any help with the (probably) simple change to my syntax would be greatly appreciated.
if (choice == 'S' || choice == 's')
{
cout << " " << numberOne << "\n-" << numberTwo <<
"\n----------------------------------------------------\n ";
//while loop that converts the numbers on the top of each stack to ints
//as long as the first stack is not empty then pops them off the stack
while(!(first.empty()))
{
//convert the number on top of the first stack to an int, store in 'one'
one = strConverter(first.top());
//convert the number on top of the second stack to an int, store in 'two'
two = strConverter(second.top());
//pop both numbers
first.pop();
second.pop();
//add both numbers and store in 'total'
total += one - two;
//equate 'onesCol' to modulus of ten of 'total'
onesCol = total %10;
//push 'onesCol' onto result stack
result.push(onesCol);
//get the new total each loop
total = (total / 10) %10;
}
//while loop that displays the intermediate totals of each loop as long
//as the result stack is not empty
while(!(result.empty()))
{
//store the top number of result stack in integer form into 'holder'
holder = (int)result.top();
//display value of 'holder'
cout << holder;
//pop the top number from the result stack.
result.pop();
}
cout << "\n\n ";
system ("PAUSE");
}