Link to home
Start Free TrialLog in
Avatar of WestonGroup
WestonGroup

asked on

How to align numbers in an array

I have 2 arrays that produce this output

joe 10
terry 23
bobby 45

how can I align the numbers so it looks like this

joe      10
terry   23
bobby 45

now I don't know what numeric values will be entered so each time the program runs different numbers could be entered  so it may not just be 2 digits may be 1 digit or 3 digits or digit with decimal point
Avatar of Infinity08
Infinity08
Flag of Belgium image

>> how can I align the numbers

One option is to use tabs instead of spaces :

        cout << name << "\t" << value << endl;

Another is to use setw :

        #include <iomanip>

        cout << setw(20) << name << setw(10) << value << endl;
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WestonGroup
WestonGroup

ASKER

what about for the input
cout << name <<endl;
cin  >> age ;

name is array
age is array
they are both in a loop for say 12 names

so on the screen you see the input can you format that as well?

nevermind figured it out

thanks
>> nevermind figured it out

Nice ;)