There probably is a simple answer to my stupid question, but I just can't seem to think logically right now.
What I have so far is a function to create a 2D array (based on the dimensions the user enters) and generate a random number for each element of the array.
This next part is where I get stuck...
How do I move this 2D array into another function that will export it into a text file?
If I was right and there is an easy solution, could you still show me how to do it. I'm more of a visually learner.
-Thanks
# include <iostream>
# include <fstream>
# include <string>
# include <ctime>
using namespace std;
void Array(int rows, int columns)
{
int **Array = new int*[rows];
for (int i = 0; i < rows; ++i)
Array[i] = new int[columns];
for (int y = 0; y < rows; y++)
{
for (int x = 0; x < columns; x++)
{
Array[y][x] = rand();
}
}
}
void File()
{
string Name;
cout << "Enter a file name you would like the array to be located under.\n";
cin >> Name;
Name = Name + ".txt";
ofstream fout(Name);
// This is where i would have the array inserted into the text file...
fout.close();
}
int main()
{
int rows, columns;
cout << "Input the number of columns you would like to have in the array. \n";
cin >> columns;
cout << "Input the number of rows you would like to have in the array. \n";
cin >> rows;
srand(time(NULL));
Array(rows, columns);
File();
system("pause");
return (0);
}