#include<iostream>
#include<cstddef>
using namespace std;
typedef int* IntArrayPtr;
void getSize(int& size1, int& size2);//Function declaration for getSize
void createArrays(int& size1, int& size2);//Function declaration for createArrays
void fillArrays(int& size1, int& size2);//Function declaration for fillArrays
int main()
{
int size1;//Variable that will be passed from one function to another
int size2;//Variable that will be passed from one function to another
getSize(size1, size2);//Funcion call for getSize
createArrays(size1, size2);//Function call for createArrays
fillArrays(size1, size2);//Function call for fillArrays
return 0;
}
void getSize(int& size1, int& size2)//Function definition for getSize
{
cout << "\nEnter the size of the first number to be added:" << endl;//Asks user to input the size of the number( number of digits) to use to create a dynamic array
cin >> size1;//Input from user
//cout << size1 << endl;//Test to show input is correct
cout << "\nEnter the size of the second number to be added:" << endl;//Asks user to input the size of the number( number of digits) to use to create a dynamic array
cin >> size2;//Input from user
//cout << size2 << endl;//Test to show input is correct
}
void createArrays(int& size1, int& size2)//Function definition for createArray
{
int* a = NULL;//Sets pointer a to NULL
a = new int[size1];//Sets pointer a equal to new int[size1] where the size is that of the number entered by the user
for ( int i = 0; i < size1; i++ )
{
a[i] = 0;//Fills all elements to zero.
cout << a[i];//Test to outpt a[i] to make sure array is filled with 0's
}
cout << endl;
int* b = NULL;//Sets pointer b to NULL
b = new int[size2];//Sets pointer b equal to new int[size2] where the size is that of the number entered by the user
for ( int i = 0; i < size2; i++ )
{
b[i] = 0;// Fills all elements to zero.
cout << b[i];//Test to outpt b[i] to make sure array is filled with 0's
}
cout << endl;
}
void fillArrays(int& size1, int& size2)//Function definition for fillArrays
{
int input1, input2;//Local variables that may be moved to a global position
cout << "\nPlease enter your first non-negative " << size1 << " digit number to add: " << endl;//Prompt asking the user for their non-negative number of the size they previously entered
cin >> input1;//Input from user
//cout << input2 << endl;//Test to make sure data entered is correct
cout << "\nPlease enter your second non-negative " << size2 << " digit number to add: " << endl;
cin >> input2;//Input from user
//cout << input2 << endl;//Test to make sure data entered is correct
}
The problem works as such: The user enters the size of the array that will be created. I have this part worked out and passed the variable to the function that will create the array. Then the array pointer should be passed to the function that will ask the user for his two number that he wants to add together. This is where I am having the difficulties, I am trying to pass the pointer to the dynamic array and everything I have bee trying is not working. I thought I would ask for some help to see if I can be able to get this to work the way it is suppose to.