i wrote this function readBig. It's purpose is to scan a number from the user as a string and converts each element of the string into an int and stores it in an int array then reverses the elements so the ones position is in n[0] tens position is in n[1] ect.. which is fine I've got that working fine. The only thing is, in my main program this function is called twice and i've got another function whose purpose is to add the two arrays and store the sum in a third array. I haven't gotten that far yet, I'm stuck just trying to print my two arrays, every time i try to print the first array it gives me the elements of the second array and it prints a bunch of nonsence for the second array... what do i need to do?
PS-not allowed to use pointers..
#include <iostream>
#include<string>
using namespace std;
//This program will test three functions capable of reading, adding,
//and printing 100-digit numbers.
int readBig(int[]);
void printBig(int[]);
void addBig(int[], int[]/*, int[]*/);
const int MAX_DIGITS = 4;
int main()
{
// Declare the three numbers, the first, second and the sum:
int numbr1[MAX_DIGITS], numbr2[MAX_DIGITS], sum[MAX_DIGITS];
cout << "Please enter a number up to "<<MAX_DIGITS<< " digits: ";
readBig(numbr1);
cout << "Please enter a number up to "<<MAX_DIGITS<< " digits: ";
readBig(numbr2);
addBig(numbr1, numbr2, sum);
//printBig(num1);
//cout << "\n+\n";
//printBig(num2);
//cout << "\n=\n";
//printBig(sum);*/
system ("PAUSE");
return 0;
}
//////////Read Function
int readBig(int[])
{
string num;
int n[MAX_DIGITS],i;
cin>>num;
for(i=0;i<MAX_DIGITS;i++)
{
n[i]=num[MAX_DIGITS-1-i]-'0';
cout<<"n["<<i<<"]"<<n[i]<<"\n";
}
}
///////addBig
void addBig(int [],int [],int [])
{
int i,sum[MAX_DIGITS],numbr1[MAX_DIGITS],numbr2[MAX_DIGITS];
for(i=0;i<MAX_DIGITS;i++)
{
cout<<"num1["<<i<<"]"<<numbr1[i]<<"\n";
cout<<"num2["<<i<<"]"<<numbr2[i]<<"\n";
//sum[i]=num1[i]+num2[i];
//cout<<"sum["<<i<<"]="<<sum[i]<<"\n";
}
}