Good point on the "i", I don't know that changed when I copy and pasted it. They're all capital. I am currently having a problem in my program when I add the two arrays. It displays the correct answer, and the ones carry over correctly, but I get an error message saying, "Run-Time check failure #2- Stack around variable 'SumArray' was corrupted" This is the current code
Code:
#include <iostream>
using namespace std;
void GetNumbers();
void AddNumbers(int[], int[],int[], const int);
void DisplayResults(int[], int[], int[], const int);
const int SIZE = 20;
void main ()
{
char FirstNumber = 0;
char SecondNumber = 0;
char Number = 0;
char Sum = 0;
char Continue;
do
{
cout << "Please enter first number ==> ";
GetNumbers();
cout << "\nContinue 'Y' or 'N' ==> ";
cin >> Continue;
}
while (Continue == 'Y');
}
void GetNumbers()
{
char Number;
int I, K = 0;
int FirstArray[SIZE];
int SecondArray[SIZE];
int SumArray[SIZE];
int TempArray[SIZE];
cin >> Number;
for (I = 0; I < SIZE; ++I)
{
FirstArray[I] = 0;
SecondArray[I] = 0;
TempArray[I] = 0;
}
I = 0;
while (Number != '\n' && I < SIZE)
{
TempArray[I] = Number - '0';
++I;
cin.get(Number);
}
for (K = SIZE - 1, --I; I >= 0; --I, --K)
FirstArray[K] = TempArray[I];
cout << "Please enter second number ==> ";
cin >> Number;
I = 0;
while (Number != '\n' && I < SIZE)
{
TempArray[I] = Number - '0';
++I;
cin.get(Number);
}
for (K = SIZE - 1, --I; I >= 0; --I, --K)
SecondArray[K] = TempArray[I];
AddNumbers(FirstArray, SecondArray, SumArray, SIZE);
}
void AddNumbers(int FirstArray[], int SecondArray[], int SumArray[], const int SIZE)
{
for (int I = 0; I <= SIZE; ++I)
{
if (FirstArray [I] + SecondArray [I] > 9)
{
SumArray[I] = (FirstArray [I] + SecondArray [I]) % 10;
SumArray[I - 1] += 1;
}
else
SumArray[I] = FirstArray [I] + SecondArray [I];
}
DisplayResults(FirstArray, SecondArray, SumArray, SIZE);
}
void DisplayResults(int FirstArray[], int SecondArray[], int SumArray[], const int SIZE)
{
int I;
for (I = 0; I < SIZE; I++)
cout << FirstArray[I];
cout << "\n";
for (I = 0; I < SIZE; I++)
cout << SecondArray[I];
cout << "\n====================" << endl;
for (I = 0; I < SIZE; I++)
cout << SumArray[I];
}
Like I said, the program runs, but when the answer is outputted I get the run-time error. Any ideas? When I run the debugger it tells me that the Array is corrupted after it outputs it from DisplayResults.