C++ brehs I need some consultation. I'm trying to figure out where I'm going wrong here.
Here's my code:
How do I get my output to look like the expected output.
The yellow arrows in the "expected output" means that my code is missing a new line. The yellow without arrows in the "expected output" means that I shouldn't have white space there.
Pretty much there's something wrong with my code towards the end where you have to formate the output by using setw().
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> //stream manipulation library
#include <fstream>
using namespace std;
int main() {
ifstream inFS;
ofstream outFS;
istringstream inSS;
string dataTitle;
string col1Header;
string col2Header;
string dataPointstr;
int dataPointint;
string dataPointemp;
string inStream1;
int inStream2;
//Prompts the user for a title for data then Outputs the title.
cout << "Enter a title for the data:" << endl;
getline(cin,dataTitle);
cout << "You entered: " << dataTitle << "\n" << endl;
//Prompts the user for the first column's header then outputs the column's header.
cout << "Enter the column 1 header:" << endl;
getline(cin,col1Header);
cout << "You entered: " << col1Header << "\n" << endl;
//Prompts the user for the second column's header then outputs the column's header.
cout << "Enter the column 2 header:" << endl;
getline(cin,col2Header);
cout << "You entered: " << col2Header << "\n" << endl;
outFS.open("novels.txt");
cout << "Enter a data point (done, -1 to stop input):" << "\n" << endl;
while (getline(cin, dataPointstr, ',')) { //Loop iterates as long as user doesn't input done, -1
if (dataPointstr == "done" || dataPointemp == "-1") {
break;
}
getline(cin, dataPointemp, '\n');
inSS.clear();
inSS.str(dataPointemp);
inSS >> dataPointint;
outFS << dataPointstr << "," << dataPointint << endl; //writes dataPointstr and dataPointint to novels.txt
}
outFS.close();
inFS.open("novels.txt");
cout << setw(33) << dataTitle << endl;
cout << left << setw(20) << col1Header << "|";
cout << right << setw(23) << col2Header << endl;
cout<<"--------------------------------------------" << endl;
while (getline(inFS,inStream1, ',')) {
inFS >> inStream2;
if(inFS.eof()){
break;
}
cout << left << setw(20) << inStream1 << "|";
cout << right << setw(23) << inStream2;
}
cout << "\n" << endl;
inFS.close();
inFS.open("novels.txt");
while (getline(inFS,inStream1, ',')) {
inFS >> inStream2;
if(inFS.eof()){
break;
}
cout << setw(20) << right << inStream1 << " ";
for(int i = 0; i < inStream2; i++) {
cout << left << "*";
}
}
return 0;
}