How do I modify my code to save the pattern that I created onto the file? #inclu
ID: 675519 • Letter: H
Question
How do I modify my code to save the pattern that I created onto the file?
#include <iostream>
#include <fstream>
using namespace std;
void displayStars(int = 0, int = 0);
int main()
{
displayStars(2,1);
displayStars(4,1);
displayStars(8,1);
displayStars(16,1);
ofstream outputFile;
outputFile.open("Pattern.txt");
outputFile.close();
return 0;
}
void displayStars(int cols, int rows)
{
for(int down = 0; down < rows; down++)
{
for (int across = 0; across < cols; across++)
cout << "+";
cout << endl;
}
}
Explanation / Answer
#include <iostream>
#include <fstream>
using namespace std;
ofstream outputFile;
void displayStars(int = 0, int = 0);
int main()
{
outputFile.open("Pattern.txt");
displayStars(2,1);
displayStars(4,1);
displayStars(8,1);
displayStars(16,1);
outputFile.close();
return 0;
}
void displayStars(int cols, int rows)
{
for(int down = 0; down < rows; down++)
{
for (int across = 0; across < cols; across++)
{
cout << "+";
outputFile << "+";
}
cout << endl;
outputFile << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.