I'm new in C++. I create a project that ask user to input their name, age, handphone number and university.
The code seems like this:
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std;
int main(){
vector<string>name;
vector<string>age;
vector<string>hpno;
vector<string>university;
string sname, sage, shpno, suniversity;
cout << "Enter name:" << endl;
getline(cin, sname);
name.push_back(sname);
cout << "Enter age:" << endl;
getline(cin, sage);
age.push_back(sage);
cout << "Enter phone number:" << endl;
getline(cin, shpno);
hpno.push_back(shpno);
cout << "Enter university:" << endl;
getline(cin, suniversity);
university.push_back(suniversity);
cout << "Name" <<" "<< "Age" <<" "<< "Handphone Number" <<" "<< "University"
<<endl;
for (int j = 0 ; j <= name.size() - 1 ; j++){
cout << name[j] << " " << age[j] << " " << hpno[j] << " " <<
university[j]<<endl;}
}
Let say the user input is like this:
Name: John Cena
Age: 20
Phone Number: 1234568903
University: Multimedia Univeristy
The Output that I want is like this:
Name Age Phone Number University
John Cena 20 1234568903 Multimedia University
But the Output that I get is like this:
Name Age Phone Number University
John Cena 20 1234568903 Multimedia University
How to make the width of header synchronize with the width of content ?