I'm working on a homework question that is similar to this script I wrote, but the output isn't coming out the way I would like.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int iRow = 4;
const int iCol = 6;
enum carType {GM, FORD, TOYOTA, BMW, NISSAN, VOLVO};
enum colorType {RED, BROWN, BLACK, WHITE, GRAY};
char inStock[iRow][iCol];
int row, col;
for (row = 0; row < iRow; row++)
{
for (col = 0; col < iCol; col++)
inStock[row][col] = 'M';
}
for (row = 0; row < iRow; row++)
{for (col = 0; col < iCol; col++)
cout << setw(10) << inStock[row][col];
cout << " " << endl;
}
system("Pause");
return 0;
}
|
I would Like the output to look something like:
GM FORD TOYOTA BMW NISSAN VOLVO
RED
BROWN
BLACK
WHITE
GRAY |
Last edited on
using ENUM only lets you use a "word" instead of number, for example, using GM and RED is equivalent to using the integer 0 (not the digit 0).
So what you need to do is store the actual names in a string array if you want to display the names more than once.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char * cart[] = {"GM", "FORD", "TOYOTA", "BMW", "NISSAN", "VOLVO"};
char * colort[] = {"RED", "BROWN", "BLACK", "WHITE", "GRAY"};
int i;
for (i = 0; i < 6; i++) cout << setw(10) << cart[i];
for (i = 0; i < 5; i++) cout << endl << colort[i];
return 0;
}
|
Can you "fill" the cells of this table now?
EDIT: Don't use
system("Pause"); it will offend some members :D
But they're probably right.
Last edited on