My quest, to put 100 random numbers in ten rows of ten. Then output the same to the screen and a file. My screen output is working,yeah! Text file, not so much. The data is getting there but not formated. If word wrap is off it's a single row. If word wraps on, well ... it wraps. I've considered sizing the notebook window to wrap at the tenth character but I don't think the TA working on his Phd will buy it. Help please! My code for this portion is below:
Code:
void tenByTen(int firstArray[])
{
char yourFileName [80];
int d1, d2;
//Prompt user for file name to store array
cout << "Enter name of file to store your randomly generated numbers: " << endl;
cin >> yourFileName;
ofstream outfile (yourFileName, ios::out);//create and open file
if (!yourFileName)//errorcheck
{
cout << "Error opening your file " << endl;
}//close error check
//fomat array output to 10 x 10
for (d1 = 0; d1 <= 9; d1++)
{
for (d2 = 0; d2 <= 9; d2++)
{
cout << setw(5) << firstArray[(d1 * 10) + d2];//write to screen
outfile << setw(4) << firstArray[(d1 * 10) + d2];//write to file
}//close nested for
cout << endl;
}//close for
outfile.close();
}//close tenBy
Comment