Hello, I am writing a program that reads 2 input files, converts them into 2 arrays, and then merges the 2 arrays into 1 array in sequential order without any duplicates. I seem to be getting the message after asking the user what it's input files and output files are called. "Run-Time Check Failure #2 - Stack around the variable 'array1' was corrupted."
I'm also getting an error that it cannot open my .exe file (Linker Tools Error LNK1168)

Does anyone see what is wrong with my code?

Thanks!

Code:
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
using namespace std;

void getInput(string prompt, ifstream& fileVariable);
void getOutput(string prompt, ofstream& fileVariable);





int main()
{
	ifstream inputFile1;
	ifstream inputFile2;
	ofstream outputFile;

	int array1[20] = {};
	int array2[20] = {};
	int finalArray[40] = {};
	int array1elements = -1;
	int array2elements = -1;
	int array1index = 0;
	int array2index = 0;



	getInput("What is the name of the first input file? ", inputFile1);

	do
	{
		inputFile1 >> array1[array1elements];
		array1elements++;
	} while (!inputFile1.eof());
	getInput("What is the name of the second input file? ", inputFile2);

	do
	{
		inputFile2 >> array2[array2elements];
		array2elements++;
	} while (!inputFile2.eof());
	getOutput("What is the name of the output file? ", outputFile); // the error occurs somewhere below this point


		do
		{
			if (array1elements = 0)
			{
				outputFile << array2[array2index] << " ";
				array2index++;
				array2elements--;
			}
			else if (array2elements = 0)
			{
				outputFile << array1[array1index] << " ";
				array1index++;
				array1elements--;
			}
			else if (array1[array1index] == array2[array2index])
			{
				outputFile << array1[array1index] << " ";
				array1index++;
				array2index++;
				array1elements--;
				array2elements--;
			}
			else if ((array1[array1index]) > (array2[array2index]))
			{ 
				outputFile << array2[array2index] << " ";
				array2index++;
				array2elements--;
			}
			else
			{
				outputFile << array1[array1index] << " ";
				array1index++;
				array1elements--;
			}
		} while ((array1elements > 0) || (array2elements > 0));




	inputFile1.close();
	inputFile2.close();
	outputFile.close();
    return 0;
}

void getInput(string prompt, ifstream& fileVariable)
{
	string fileName(" ");
	do
	{
		cout << prompt;
		cin >> fileName;

		fileVariable.open(fileName);

		if (fileVariable.fail())
		{
			cout << "Error, incorrect file name. Please try again..." << endl;
		}
	} while (fileVariable.fail());
}

void getOutput(string prompt, ofstream& fileVariable)
{
	string fileName(" ");

	do
	{
		cout << prompt;
		cin >> fileName;

		fileVariable.open(fileName);

		if (fileVariable.fail())
		{
			cout << "Error, please try again..." << endl;
		}
	} while (fileVariable.fail());
}