### Homework help

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.

FOR SOME RESON THE SUM WONT ADD OR OUTPUT THOUGH
.
This is what i have so far:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106`` ``````#include using namespace std; const int MAXIMUM_DIGITS = 20; void input_Large_Int (int a[], int& size_of_A); //input function for the two big integers void output_Large_Int(int a[], int size_of_A); //output function for the two big integers and the sum integer void add(int a[], int size_of_A, int b[], int size_of_B, int sum[], int & size_Sum); //add function for the big integers' sum int main() { //Declare arrays int a[MAXIMUM_DIGITS], b[MAXIMUM_DIGITS], sum[MAXIMUM_DIGITS]; //Declare arrays' size int size_of_A, size_of_B, size_Sum; //declare char type for program answer response char answer; for(int i = 0; i < MAXIMUM_DIGITS - 1; i++) { a[i] = 0; b[i] = 0; sum[i] = 0; } //perform do-while loop until user answers with "n" or "N" do { //accept first user integer input input_Large_Int(a, size_of_A); //accept second user integer input input_Large_Int(b, size_of_B); //add arrays add(a, size_of_A, b, size_of_B, sum, size_Sum); //display the integers that were added and their sum cout << "The sum of \n"; output_Large_Int(a, size_of_A); cout << " and "; output_Large_Int(b, size_of_B); cout << " is "; output_Large_Int(sum, size_Sum); cout << "\n\n"; //ask if user wishes to continue cout << "Add two more? (y or n): "; cin >> answer; } while (answer == 'y' || answer == 'Y'); system("pause"); return EXIT_SUCCESS; } //define input for the big integer function void input_Large_Int(int a[], int& size_of_A) { char digit[MAXIMUM_DIGITS]; char change; int i = 0; cout << "Please enter a positive integer - no more than 20 digits: "; cin.get(change); if (change == '\n') cin.get(change); while (isdigit(change) && i < MAXIMUM_DIGITS) { digit[i] = change; i++; cin.get(change); } size_of_A = i; int j = 0; //convert ASCII values to actual values with while-loop while (i > 0) { i--; a[j] = digit[i] - '0'; j++; } } //define output for the big integer with a for-loop to display each digit void output_Large_Int(int a[], int size_of_A) { for (int i = 0; i < size_of_A; i++) cout << a[size_of_A - i - 1]; } void add(int a[], int size_of_A, int b[], int size_of_B, int sum[], int &size_Sum) { int i; for(i = 0; i < MAXIMUM_DIGITS - 1; i++) { sum[i] = (a[i] + b[i]) % 10; sum[i + 1] = (a[i] + b[i]) / 10; i++; } if ((a[i] + b[i])/20 > 0) { cout << "INTEGER OVERFLOW in the sum, NOT accurate.\n" << endl; } ``````
You never give a value to size_Sum
Topic archived. No new replies allowed.