I need to align the Item# Itemname Price and Etc.

So I first tried it with \t and it align very well, but when I typed a much longer itemname it all got jumbled up. Can someone tell me what to do?


cout<<"\n*******OFFICIAL RECEIPT*******";
cout<<"\nDate: "<<date<<endl;
cout<<"Cashier: "<<name<<endl;
cout<<setw(20)<<"Item Name Price Qty Total";
cout<<setw(20)<<"\n#1"<<object1<<"\t"<<a<<"\t"<<a2<<"\t"<<a3;
cout<<setw(20)<<"\n#3"<<object2<<"\t"<<b<<"\t"<<b2<<"\t"<<b3;
cout<<setw(20)<<"\n#3"<<object3<<"\t"<<c<<"\t"<<c2<<"\t"<<c3;
cout<<setw(20)<<"\n\n\t\t\t\tGrand Total\t"<<d;
cout<<setw(20)<<"\n\n\t\t\t\tAmount Received\t"<<amount;
cout<<setw(20)<<"\n\n\t\t\t\tChange\t"<<change;
cout<<"\n********** E N D **************";
Since you failed to use meaningful variable names or even show us samples of your input and output the only guess that you should either "trim" the item name or use setw() instead of your tab strings, or some combination of the two.
Topic archived. No new replies allowed.