Hello, I am currently trying to write a program that will display a chart for the inventory of a car dealer. Here are the major points of the assignment, the ones Im having trouble on:
Write a program to be able to display the instock table as instructed below :
2. Declare an enum type for row index text names
a. Enum Type name: MAKERS
b. Enum members: Ford, BMW, Volvo, Chevy, Cadillac, Hyundai
3. Declare an enum type for column index text names.
a. Enum Type name: COLORS
b. Enum members: Red, Brown, Black, White, Gray

a. Declare a MAKERS enum variable as maker
i. Use maker as row index variable of the array
b. Declare a COLORS enum variable as color
i. Use color as column index variable of the array
c. Write a nested for-loops to display the inventory table as shown above.
d. To be able to convert the enum element names to test, write two conversion functions
i. void convertToMakers(MAKERS m)
1. Displays maker names – use switch function.
ii. void convertToColors (COLORS c)
1. Displays color names – use switch function.

Currently the program displays the header and the array, but Im having a lot of trouble with actually using the enums. I understand how enums are supposed to work in simple code but am having trouble applying it to an array. Any help or suggestions are much appreciated.

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

const int ROW_MAX = 6;
const int COLUMN_MAX = 5;

void reportHeading ( ostream& outputfile);
void printInventory (ostream& outputfile, int carsInStock[ROW_MAX][COLUMN_MAX]);

int main () {

	enum MAKERS	{FORD,BMW,VOLVO,CHEVY,CADILLAC,HYUNDAI};
	enum COLORS	{RED,BROWN,BLACK,WHITE,GREY};


	int carsInStock[ROW_MAX][COLUMN_MAX] = {{18,11,15,17,10},
											{16,6,13,8,3},
											{9,4,7,12,11},
											{10,7,12,10,4},
											{12,10,9,5,6},
											{11,13,7,15,9}};
	
	ofstream outputfile ("PJ712_output.txt");
		if (!outputfile)
	{
		cerr <<"Could not open the output file.\n";
		return -2;
	}


	outputfile <<fixed<<showpoint<<setprecision(2);
	reportHeading (outputfile);
	printInventory (outputfile, carsInStock );

}

void reportHeading ( ostream& outputfile){
	outputfile << "Cars in Stock Inventory" << endl;
	outputfile << "By Yelena Sergevnina \n\n" << endl;
}

void printInventory (ostream& outputfile, int carsInStock[ROW_MAX][COLUMN_MAX]){
	MAKERS = maker;
	COLORS = color;
	for( int i = 0; i < ROW_MAX; i++ )
	{
		for ( int j = 0; j < COLUMN_MAX ; j++ )
		{
		 outputfile << setw(12) <<  carsInStock[i][j];
		}
		outputfile << endl;
	}
}

If you want to use the enums in the other functions, they need to be global:

enum MAKERS	{FORD,BMW,VOLVO,CHEVY,CADILLAC,HYUNDAI};
	enum COLORS	{RED,BROWN,BLACK,WHITE,GREY};

int main () {

What are these lines supposed to do?

MAKERS = maker;
	COLORS = color;

Here is a simple example of using enums:

#include <iostream>

enum PointType { GOOD, BAD, UNINFORMATIVE };
	
int main(int argc, char *argv[])
{
  PointType A = GOOD;
  
  if(A == GOOD)
    std::cout << "good" << std::endl;
  else
    std::cout << "not good" << std::endl;

  if(A == BAD)
    std::cout << "not working" << std::endl;
  else
    std::cout << "working" << std::endl;
	
	return 0;
}

It demonstrates how create a variable of the enum type as well as perform some comparisons.

Hope that helps,

Dave

Thanks, that kind of helped. Im mostly trying to figure out how I would make the enum represent the rows and columns in the array so that it would look something like this, just an example:

red black white
chevy 2 3 2

ford 4 4 2

im able to get the actual numbers to come out as a table just not sure how the make the names appear.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.