Listing two arrays

My homework is asking me to list two array into two columns, I was able to get the program to list the two arrays into the two columns but I don't know how to make the second column look nice.

This is my code.


#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()

{
const string cars[10] = {"Red", "Blue", "Black", "White", "Gray", "Green", "Yellow", "Brown", "Silver", "Other"};
const int number[10] = {100, 90, 180, 230, 130, 20, 30, 50, 160, 10};

cout << "There are 1000 cars in a lot, I will give you a list of the colors and how many cars there are of that color. \n";
cout << "Colors of cars: Numbers of cars:" << endl;
for (int i=0; i<10; i++)
{
cout << cars[i] << " " << number[i] << endl;
}




return 0;
}
Last edited on
You could use the io manipulator setw() to set the width of your columns. I assume that was what you meant.
Check out iomanip under the input/output reference of this site. You have already included the relevant header.
Okay I'll try it, thank you.
closed account (48T7M4Gy)
There are millions of options, this is just one:

cout << setw(10) << cars[i] << setw(10) << number[i] << endl;
Topic archived. No new replies allowed.