How to print 3 arrays in column format

trying to print this in column format and i'm struggling
this prints like this now                     this is how i want it to print
Employee Name                             employee name          employee Id
joe                                                 joe                                   3
mike                                               mike                                4

employee id
3
4
cout <<"Employee Name";
         cout << endl;
         for(int i = 0; i < 7; i++)
         {        
         cout << employee_names[i] << endl;
         }
         cout << endl;
         cout <<"Employee ID";
         for(int i = 0; i < 7; i++)
         {
         cout << empid[i] << endl;
         }
         cout << endl;

I just can't seem to understand how arrays print out and how to manipulate data the way I want
WestonGroupAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenData Warehouse Architect / DBACommented:
Hi WestonGroup,

Printing tab characters (\t) between items is the easiest, though it doesn't always align exactly as you might want.

And then there's the issue of left/right aligning data within its own field.  Text is usually left aligned, integers right aligned, and real numbers align on the decimal point.

The C output routines are very good at it, but that's considered 'throwback'

  fprintf (stdout, " %-20s     %4d\n", TextValue, IntegerValue);


Good Luck,
Kent
0
Infinity08Commented:

cout << left << setw(20) << "Employee name" << setw(15) << "Employee ID" << endl;
for (int i = 0; i < 7; ++i) {
    cout << left << setw(20) << employee_names[i] << setw(15) << empid[i] << endl;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
Use <iomanip>, e.g.


#include <iomanip>
using namespace std;
 
cout  << setw(16) <<"Employee Name" << setw(16) <<"Employee ID";
         cout << endl;
         for(int i = 0; i < 7; i++)
         {        
         cout  << setw(16) << employee_names[i]  << setw(16) empid[i] << endl;
         }
 
 
// play with '16' to suit your needs

Open in new window

0
jkrCommented:
Ooops, that should have been
#include <iomanip>
using namespace std;
 
cout  << setw(16) <<"Employee Name" << setw(16) <<"Employee ID";
         cout << endl;
         for(int i = 0; i < 7; i++)
         {        
         cout  << setw(16) << employee_names[i]  << setw(16) << empid[i] << endl;
         }
 
 

Open in new window

0
Deepu AbrahamR & D Engineering ManagerCommented:
cout <<"Employee Name";
cout<<"\t";
cout <<"Employee ID";
cout<<endl;
for(int i = 0; i < 7; i++)
 {        
         cout << employee_names[i] ;
         cout<<"\t"; //Tab seperated
        cout << empid[i] << endl;
 }

Does it help?
Best Regards,
DeepuAbrahamK
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.