Hello. I'm supposed to store the two numbers in two int arrays of size 30, one digit per array element. If the number is less than 30 in length, enter enough leading zeroes (to the left) to make number 30 digits long. I will need a loop to add the digits in corresponding array elements and carry digits if needed.
The first digit will be read into A[0], second in A[1] and so on until I hit end of line. Then, here's where it get complicated. My teacher said I should make sure the total number of digits read in is less than 30 (I thought the numbers should be up to 30). After I read in the list, I should push the list down so that the last digit is in A[29] and the second last in A[28] and so on. How do I do that?
Afterwhich, I will add the corresponding digits from both arrays: A[29] to B[29] etc. I need to carry numbers if the sum is greater than 9. I'm confused on what to do....here's what I have so far.
//File: lab8b.cpp
/*Purpose: to read two integers up to 30 digits each,
add them together, and display the result*/
#include <iostream>
#include <conio.h>
#define SIZE 30
using namespace std;
void inputValue1(long int[]);
void inputValue2(long int[]);
void Sum(long int[]);
void main()
{
long int A[SIZE];
long int B[SIZE];
long int C[SIZE];
inputValue1(A); //function call
inputValue2(B); //function call
Sum(C); //function call
getch();
}
void inputValue1(long int A[])
{
cout << "Enter first integer (30-digit): ";
for(int i=0; i<SIZE; i++)
cin >> A[i];
}
void inputValue2(long int B[])
{
cout << "Enter second integer (30-digit): ";
for(int i=0; i<SIZE; i++)
cin >> B[i];
}
void Sum(long int C[])
{
long int i;
long int A[30],B[30];
for(i=0; i<SIZE; i++)
C[i] = A[i] + B[i];
cout << "The sum of these two integers is: " << C[i];
}