-1

I want to display output like this:

First Name: Max Last Name: Payne City: Brisbane Phone Number: 155478635

I have tried with \t and setting field width using cout.width() and setw(), but this width gets changed and are not displayed in columns properly and depends on my input length.

My code is given below:

 #include <iostream>
 #include <iomanip>
 using namespace std;



 class BillSys{

       char fname[20], lname[20], city[20], phone[11];

       public:

       void accept(){

             cout<<"Enter the name of the customer: ";
             cin>>fname>>lname; cout<<endl;
             cout<<"Enter city: ";
             cin>>city; cout<<endl;
             cout<<"Enter contact number: ";
             cin>>phone;
             cout<<endl<<endl;

      }

      void display(){

            cout<<"***Customer Details***"<<endl<<endl;
            cout<<"First Name: ";
            cout<<fname;

           //cout<<setw(10); 

           cout<<"\t";

           cout<<"Last Name: "<<lname;
           cout<<endl;

           cout<<"City: "; 
           cout<<city;
           cout<<"\t";

          //cout<<setw(10); 

          cout<<"Phone Number: "<<phone;
          cout<<endl;
      }

  };

  int main(int argc, char** argv) {

     BillSys obj;

     obj.accept();
     obj.display();
     return 0;
  }
πάντα ῥεῖ
  • 85,314
  • 13
  • 111
  • 183

1 Answers1

0

I would gather all the information in one std::string and then modify/trim the string. You might find some inspiration in http://www.cplusplus.com/reference/string/string/ and What's the best way to trim std::string?

Community
  • 1
  • 1
Anders Schou
  • 184
  • 1
  • 12