Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help figuring out how to print a block of \'O\'s to a file using nested l

ID: 3656690 • Letter: I

Question

I need help figuring out how to print a block of 'O's to a file using nested loops. The user will input a filename and one integer to be set as the height and width. I have the write to file part down, just not the printing of the block. Here is my code so far:

#include <iostream>

#include <string>

#include <fstream>

#include <cstdlib>


using namespace std;


int main()


{


ofstream fout; // declare an output file stream

string file_name;

int hw;


cout << "Enter file name: ";

cin >> file_name;


fout.open(file_name.c_str(), ios::out); // open file file_name for output


if (!fout.is_open()){

cerr << "Unable to open file " << file_name << endl;

exit(10);}


cout << "Enter an integer greater than 1: ";

cin >> hw;


if (hw <= 1){

cerr << "Incorrect input" << endl;

exit(20);}


if (hw > 1){

// need to print block of 'O's

}


fout.close();

return 0;

}



Explanation / Answer

if (hw > 1) { for(int i=1;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote