My first attempt at 2-dimensional arrays is not working out so well. We are to simply initialize an array and print out the results. My problem is that the data contains text and numbers.....column header is car color, row header is car make. I am getting error for lines 19 and 20 "error C2440: 'initializing' : cannot convert from 'const char [9]' to 'int'" and I am not sure how to get around this. I have try single quotes and double quotes around the data, but the error remains....any help would be appreciated

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>

using namespace std;

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

int carsInStock[ROW_MAX][COLUMN_MAX];

void reportheading(ofstream& outputfile);
void printInventory(int carsInStock[ROW_MAX][COLUMN_MAX], ofstream& outputfile);

int main()
{
	int carsInStock[ROW_MAX][COLUMN_MAX] = {{"In Stock", "Red", "Brown", "Black", "White", "Gray"},{"Ford",'18', '11', '15', '17', '10'},{"BMW",'16', '6', '13', '8', '3'},
	{"Volvo",'9', '4', '7', '12', '11'},{"Chevy",'10', '7', '12', '10', '4'},{"Cadillac", '12', '10', '9', '5', '6'},{"Hyundai", '11', '13', '7', '15', '9'}};

	ofstream outputfile( "Inventory.txt" );
	if( !outputfile )
	{
		cerr << "Could not open the output file.\n";
		return -2; //Terminate the program when the outout file failed.
	}
	reportheading(outputfile);
	printInventory(carsInStock, outputfile);
}
void reportheading(ofstream& outputfile)
{
	outputfile << "\t\t\t     Cars in Stock Inventory\n";
	outputfile << "\t\t\t   Reported by Patrick Nealey\n\n";
	outputfile <<endl<<endl;

}
void printInventory(int carsInStock[ROW_MAX][COLUMN_MAX], ofstream& outputfile)
{
	outputfile << carsInStock;
}

Your problem proves not that you don't have an understanding of arrays but that you do not have an understanding of how objects work. Notice at the beginning of your array declaration you put 'int' but then inside ALL of the data are STRINGS, not INTEGERS. Also if your going to make them STRINGS use double quotes: single quotes is only for single characters.

Lastly, based on the array declaration I'm having much trouble understanding exactly what your array is for.

I'm also sorry if I sounded rude in my post, no rudeness intended.

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.