Question: I have the following C++ code which needs comments for each line of code explaining what each line of code does, I am only missing

I have the following C++ code which needs comments for each line of code explaining what each line of code does, I am only missing comments for a few lines of code which am not sure how to put the comments in my own words.

#include  //allows us to use cin,cout and endl #include  //allows to read data from a file and write data to a file using namespace std; //allows us to use cin,cout and endl without having to type the prefix std:: const int NUM_DIVISORS = 5; const int DIVISORS[] = {3, 5, 7, 9, 11}; int main() // used to start the program { int num; //this variable will store the number that the user inputs ofstream outfile("numbers.txt"); // open file for writing do { cout << "Enter a positive number (-1 to stop): "; //displays text on the console prompting user to enter a number cin >> num; if (num > 0) { outfile << num << endl; // write number to file } } while (num > 0); outfile.close(); // close file ifstream infile("numbers.txt"); // open file for reading while (infile >> num) { cout << "Number: " << num << " "; for (int i = 0; i < NUM_DIVISORS; i++) { if (num % DIVISORS[i] == 0) { cout << "Divisible by " << DIVISORS[i] << ": Yes "; } else { cout << "Divisible by " << DIVISORS[i] << ": No "; } } cout << endl; } infile.close(); // close file cout << endl; return 0; //ends the main function (program) }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!