Homework Help please!

Hello so basically my project goes like this:

Write a C++ program that reads in two positive integers that are 20 or fewer digits in length and outputs the sum of the two numbers.

Your program will read the digits as values of type char so that the number 1234 is read as four characters '1', '2', '3' and '4'. After they are read into the program, the characters are changed to values of type int. The digits will be read into a partially filled array and you might find it useful to reverse the order of the elements in the array after array is filled with data from the keyboard.

Your program will perform the addition by implementing the usual pencil and paper addition algorithm. The result of the addition is stored in an array of size 20 and the result is written to screen. if the result of the addition is an integer with more
than maximum number of digits(that is more than 20 digits) then your program should issue a message saying that it has encountered "integer overflow".

You should be able to change the maximum length of the integers by changing only one globally defined constant. Include the loop that allows the user to continue to do more additions until the user says the program should end.

And I'm having issues with my code. Can't seem to figure it out, what I have so far is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  #include <iostream>
#include <cstdlib>
using namespace std;
void  reverseArr(int a[], int liu);
void addLargeInt(int a1[], int liu1, int a2[], int liu2, int sum[], int& liu_sum);

int main()
{
cin.get(next);


while(next != "\n" )
	{
	n1[index] = atoi(&next)
	char next;
	index ++;
	cin.get(next);
	}


liu = index – 1;
return 0;
}

void  reverseArr(int a[], int liu) 
{ int temp,
for(int = 0; i<= liu/2 ; i++)
	{
	Temp = a[i]
	a[i] = a[liu – i]
	a[liu – i]  = temp;
	}
}


void addLargeInt(int a1[], int liu1, int a2[], int liu2, int sum[], int& liu_sum)
{
 int cover = 0;
	liu_sum = 0; 
	int max;
if(liu1 > liu2)
	max = liu1
else max = liu2;

for (int = 0; i<=max; i++)
	{
	sum[i] = (a1[i] +a2[i])%;
	sum[i] += cover;
	sum[i]  %=  10

cover =  ?
}

if (cover = 1)
{
	sum[max+1]  = cover
	liu_sum = max + 1;
}

	else
	liu_sum = max;
Last edited on
Topic archived. No new replies allowed.