I am required to make a code that makes a pyramid with number of input lines "n" to a text file. What i figured i would do i make the program so that it makes a pyramid on the screen and then write it to a text file. This is my code thus far:

#include <iostream>
#include <fstream>
using namespace std;

int main()
ofstream data;

double n;
int i, k, j;

cout << "Input the number of lines in the pyramid as a WHOLE NUMBER: " << endl;
cin >> n;

if ( (int) n/ (double) n != 1){
cout << "Please Input a WHOLE NUMBER" << endl;
cin >> n;

}while ( (int) n/ (double) n != 1);

for (int i(1); i <= n; ++i)
for ( j = n-i; j>0; j--)
cout << " ";
data << " ";
cout << "+";
data << "+";
cout << endl;

return 0;

It makes the pyramid fine on the screen, my problem is writing it to the text file. What i tried was to input the data << after the " " and the "+" but that only puts the nth line into the text file correctly. Any help or suggestions?

Is it because you don't have {} after the for statements in both the cases? Without the braces only the next line is part of for loop. And you will also need a

data << "\n";