hi,

i need help with this:

Assume that your computer has the very limited capability of being able to read and write only single-integer digits and to add two integers consisting of one decimal digit each. Write a program that can read two integers up to 30 digits each, add these integers together, and display the result. Test your program using pairs of numbers of varying lengths.
Hint: Store the two numbers in two int arrays of size 30, one digit per array element. If the number is less than 30 digits in length, enter enough leading zeros (to the left of the number) to make the number 30 digits long.
You will need a loop to add the digits in corresponding array elements. Don’t forget to handle the carry digit if there is one!

this is the code

#include <iostream>
#include <string>
#include <conio.h>
#include <iomanip>



using namespace std;
int main()
{
	long int SIZE = 30;
	long int integer1 = 0;
	long int integer2 = 0;
	


	cout << "Enter two integers: ";
	for(int i=0; i<SIZE; i++)
		cin >> integer1;


	for(int i=0; i<SIZE; i++)
		cin >> integer2;






	getch();
	return 0;
}

What is your question ?

By the way from the code you have posted I suggest you look at a tutorial on the concept of arrays

here is a better one:
but when i debug it, it says that a stack around 'total' was corrupted

please help

#include <iostream>
#include <conio.h>

using namespace std;

void inputValue1(int[]);
void inputValue2(int[]);
void Sum(int[], int[]);
const int SIZE = 5;
void main()
{
	int val1[SIZE];
	int val2[SIZE];
	int total[SIZE]; 

	inputValue1(val1);
	inputValue2(val2);
	Sum(val1, val2); 

getch();
}

void inputValue1(int val1[])
{
	cout << "Enter the first number: ";
	for(int i = 0; i < SIZE; i++)
		cin >> val1[i];
	return;
}

void inputValue2(int val2[])
{
	cout << "Enter second integer: ";
	for(int i=0; i<SIZE; i++)
		cin >> val2[i];
	return;
}

void Sum(int val1[], int val2[])
{
	int i;
	int total[5];
	
for(i=SIZE;i>=0;i--)
if ((val2[i]+val1[i]) > 9)
{
	 val2[i-1] = val2[i-1] + 1;
}
total[i] = (val2[i]+val1[i]) % 10;

	cout << "The sum of these two integers is: " << total[i];
}

thanks in advance

Look at the hint and rewrite your input functions first.

Where did you find the second code?

What if the digits at the 0 th place for both the numbers is 9 . Can you run through the code and see how it will perform

This article has been dead for over six months. Start a new discussion instead.