I am stuck on the last part of this problem. These functions produce the desending triangles. Ex: user enters 3 the output is 3 triangles
***
**
*
**
*
* After much time I have done this, however I have hit a wall in trying to send the output to an output file. It will copy to the file fine however after every iteration of the loop the previous output is reset with the new and I don't know how to resolve this. Tried many different guess and check attempts and feel I have exhausted all other resources. Any input would be greatly appreciated. Note my fout in the drawTriangle function the problem must be with its location?
#include <iostream>
#include <fstream>
using namespace std;
void drawTriangle(ofstream & fout, int);
int main()
{
int i, number;
char filename[40];
ofstream fout;
cout << "Please enter the number of triangles you would like: " << endl;
cin >> number;
cout << endl;
cout << "Enter the file name you would like those triangles stored in: " << endl;
cin >> filename;
cout << endl;
fout.open(filename);
for (i = 1; i <= number; number--)
{
drawTriangle(fout, number);
cout << endl;
}
return 0;
}
void drawTriangle(ofstream & fout, int number)
{int i, j;
for (i = number; i > 0; i--) // outer loop row to row
{
for (j = number; j >= i; j --) // innner loop across row
cout << "*";
fout << "*";
cout << endl; // end of row newline
}
}