I am trying to output my strings column-wise using the vector iterator as shown in the attached image. For now I am just displaying a test case using the names and the cider order after which I want to replicate the same for others.
// values for controlling format
constint name_width = 15 ;
constint int_width = 7 ;
constint dbl_width = 12 ;
constint num_flds = 7 ;
const std::string sep = " |" ;
auto total_width = name_width*2 + int_width*2 + dbl_width*3 + sep.size() * num_flds ;
const std::string line = sep + std::string( total_width-1, '-' ) + '|' ;
cout<<"How many people ordered? ";
cin>>odrs; // Store number of orders
for(int i=1; i<=odrs; i++){
cout<<"Enter the name of person #"<<i<<":"<<endl;;
cin>>names; // Store names of users
odrNames.push_back(names); // Store names as entered as
cout<<"How many orders of cider did "<<names<<" have? ";
cout<<endl;
cin>>odrciderjuice; // Store Cider order item
sbCider = odrciderjuice * 5.5; // Calculate Cider order per price
odrCider.push_back(odrciderjuice); // Store Cider order item based on entry
SbCider.push_back(sbCider); // Store calculated Cider order per price
cout<<"How many orders of apple juice did "<<names<<" have? ";
cout<<endl;
cin>>odrapplejuice; // Store Juice order item
sbJuice = odrapplejuice * 4.5; // Calculate Juice order per price
odrApple.push_back(odrapplejuice); // Store Juice order item based on entry
SbJuice.push_back(sbJuice); // Store calculated Juice order per price
cout<<endl;
total = sbCider + sbJuice; // Calculate total between Cider and Juice
GTotal.push_back(total); // Store total values after calculation
cout<<endl;
}
for(vector<string>::iterator naming = odrNames.begin(); naming!= odrNames.end(); ++naming)
cout << sep << std::setw(name_width) << *naming<<"\v";
for(vector<int>::iterator ciderOdr = odrCider.begin(); ciderOdr!= odrCider.end(); ++ciderOdr)
cout <<*ciderOdr;
Using \v is not going to work. You need to print a line at a time, not a column at a time.
Instead of a bunch of separate vectors for each field you should use a struct. It's also handy to have a constructor for it to fill in the fields easier.
Below I'm using cin.getline to read the name. Since it reads an entire line, it allows the name to contain spaces. But since cin >> x leaves the "newline" behind in the input stream, you need a function for skipping the rest of the line (skip_line below).
You don't need to save the calculations since they can be done during output.