The purpose of the code is to prompt the user to enter how many connections/nets & write to a CSV file.
The code runs and writes to the CSV file on the first column but after the user is prompted to input the # of nets again, it writes on the same column instead of the next one which has the header "Connector 2" or Column B.
How do I get my code to write to the first column, move on to the next column and prompt the user to input the # of nets/connections?
Here is my code
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
int nets;
ofstream myFile;
myFile.open("My File.csv"); // Create file
myFile << "Connector 1" << "," << "Connector 2" << endl; // Headers
while (true) {
cout << "# of Nets: " << endl;
cin >> nets;
if (nets > 0) {
for (int i = 1; i <= nets; i++) {
myFile << i << endl;
myFile << ",";
}
}
else {
break;
}
}
}