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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
ASKER
nevermind figured it out
thanks
thanks
>> nevermind figured it out
Nice ;)
Nice ;)
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;