I am writing a program for class that inputs two of chars values no larger than 20. Then it adds these to Values together and prints the sum. Say this is my input Value one 123 Value two 456.
This is how i input it into program for keyboard.
3
1
2
3
"123"3
4
5
6
"465"
"579"
I have two problems.
#1 If i have to values of different size it wont work. Like if Value one is 123 and Values two is 4567. Value one has a size of 3 value two 4. In this case i need to make it put value one into array of size 4 so it would be 0123+4567 so the 7 and 3 will line up.
how can i do this?
#2 I cant get it to carry a remainder. Say value one is 39 and Value two is 21. When i run the program it prints 510 where 9+1=10 and 3+2=5. It should print 60. How can i fix this.
int size1=0,size2=0,i;
char data1;
char data2;
int *pointer1;
int *pointer2;
int *pointer3;
cin>>size1; //ENTER SIZE OF VALUE ONE
pointer1=new int[size1];
for (i=0; i<size1; i++)
{
cin>>data1; //ENTER VALUE ONE AS CHARS
data1=data1-48; //CONVERTS CHARS TO INTS
pointer1[i]=data1; // FILLS ARRAY WITH VALUE ONE
}
for (i=0; i<size1; i++)
{cout << pointer1[i];} //PRINTS VALUE ONE
cin>>size2; //ENTER SIZE OF VALUE TWO
pointer2=new int[size2];
for (i=0; i<size2; i++)
{
cin>>data2; //ENTER VALUE TWO AS CHARS
data2=data2-48; //CONVERTS CHARS TO INTS
pointer2[i]=data2; // FILLS ARRAY WITH VALUE TWO
}
for (i=0; i<size2; i++)
{cout << pointer2[i];} //PRINTS VALUE TWO
pointer3=new int[size2+1];
for(i=0; i<size2+1; i++)
{
pointer3[i]=*pointer1+*pointer2; //ADDs VALUE ONE AND TWO BY COLUMN
++pointer1;
++pointer2;
}
cout<<" "<<endl;
for (i=0; i<size2; i++)
{cout << pointer3[i];}// PRINTS SUM
return 0;
}