Hi first here is my program i want to make all the output of my program is segregate in column
Here is the Output of my program right now i want to make the output is all line in in age and section:
#include<iostream>
#include <iomanip>
using namespace std;
struct student {
string fullname[200];
string course[200];
int age[200];
};
student p1;
main()
{
int input;
cout<<"How many Student do you like to Add:";
cin>>input;
for(int i=0; i!=input; i++)
{
cout<<"----------Input #"<<i+1<<"----------"<<endl;
cout<<"Enter Name: ";
cin.ignore();
getline (cin,p1.fullname[i]);
cout<<"Enter Age: ";
cin>>p1.age[i];
cout<<"Enter Section: ";
cin>>p1.course[i];
}
cout<<"\n\n----------------- List of Student that is 19 Above -----------------"<<endl;
cout<<"\nFull Name:"<<setw(20)<<"Age:"<<setw(20)<<"Section:"<<endl;
for(int i=0; i!=input; i++)
{
if(p1.age[i] >= 19)
{
cout<<p1.fullname[i]<< setfill(' ') <<setw(20) <<p1.age[i]<< setfill(' ') <<setw(20)<<p1.course[i]<<endl;
}
}
system("PAUSE");
}
You need to apply setfill
and setw
before the field that you want to write. And you need to apply it also to fullname
.
cout << setfill(' ')
<< setw(20) << p1.fullname[i]
<< setw(20) << p1.age[i]
<< setw(20) << p1.course[i]
<< endl;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.