I am trying to the output of my strings using the vector iterator side by side in column manner as shown in the attached image. for now i am just displaying a test case using the names and the cider order after which to replicate for the others.desired output screenshot
Below is my current code:
// values for controlling format
const int name_width = 15 ;
const int int_width = 7 ;
const int dbl_width = 12 ;
const int 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;
Aucun commentaire:
Enregistrer un commentaire