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;
}