I am having a hard time getting this program (my homework assignment) to compile. I have looked it over a million times. The program is supose to read an inventory of an art gallery from "art.dat" into a struct (the Type and Place have to be enum types), and then a user has to be able to type in an artist name and get an output of all of the pieces of work that are listed for that artist.

I NEED HELP PLEASE!!! WHAT AM I DOING WRONG!!!

#include<iostream>
#include<fstream>
#include<cctype>

using namespace std;

enum Type {OIL, WATERCOLOR, PASTEL, ACRYLIC, PRINT, COLORPHOTO, BWPHOTO};
enum Place {MAIN, GREEN, BLUE, NORTH, SOUTH, ENTRY, BALCONY};

struct Size
{
  int Height;
  int Width;
};

struct ArtWork
{
  string  Artist;
  string  Title;
  Type    Medium;
  Size    WorkSize;
  Place   Room;
  float   Price;
};

const int MAX_ARTWORK = 120;

void search(ArtWork&);

int main()
{
  char      YN;
  bool      test;
  ArtWork   collection[MAX_ARTWORK];
  ifstream  inFile;

  inFile.open("art.dat");

  for(int i=0; i < MAX_ARTWORK; i++)
    {
      inFile.get(collection[i].Artist);
      inFile.get(collection[i].Title);
      inFile.get(collection[i].Medium);
      inFile.get(collection[i].WorkSize);
      inFile.get(collection[i].Room);
      inFile.get(collection[i].Price);
    }


  test = true;

  do
    {
      search(collection[]);
      cout << "Would you like to look up another artist? (y/n)" << endl;
      cin >> YN;

      if (tolower(YN) == 'n')
    {
      inFile.close();
      return 0;
    }
    } while (test == true);
}

void search(ArtWork&collection[])
{
  string   artist, medium, room;
  int      i;

  cout << "Enter artist name: " << endl;
  cin >> artist;

  cout << "Artwork found by that Artist:" << endl;
  for(i=0; i < MAX_ARTWORK; i++)
    {
      int count = 0;
      if (collection[i].Artist == artist)
    {
      cout << "Title: " << collection[i].Title << endl;
      switch (collection[i].Medium)
        {
        case OIL : medium = "Oil";
          break;
        case WATERCOLOR: medium = "Watercolor";
          break;
        case PASTEL: medium = "Pastel";
          break;
        case ACRYLIC: medium = "Acrylic";
          break;
        case PRINT: medium = "Print";
          break;
        case COLORPHOTO: medium = "Color Photo";
          break;
        case BWPHOTO: medium = "Black & White Photo";
        }

      cout << "Medium: " << medium << endl;
      cout << "Work Size: " << collection[i].WorkSize.Height << "X" << collection[i].WorkSize.Width << endl;
      switch (collection[i].Room)
        {
        case MAIN: room = "Main";
          break;
        case GREEN: room = "Green";
          break;
        case BLUE: room = "Blue";
          break;
        case NORTH: room = "North";
          break;
        case SOUTH: room = "South";
          break;
        case ENTRY: room = "Entry";
          break;
        case BALCONY: room = "Balcony";
        }
      cout << "Room: " << room << endl;
      cout << "Price: " << collection[i].Price << endl;
      count= count++;
    }
    }
  if (count == 0)
    cout << "There was no artwork found by that artist." << endl;
  return;
}

I NEED HELP PLEASE!!! WHAT AM I DOING WRONG!!!

Not reading the compiler's error messages is the first thing.

When dealing with arrays as arguments to function, you do not use the &.

void search( ArtWork [] );   // not ( ArtWork & ), thats for passing a single item by reference

Similarly, when calling the function, use just the array's name.

search( collection );  // not ( collection[] )

Where you read the file, you are using the input form for C-style (character array based) strings, which does not work for your C++ strings.

get( inFile, collection[i].Artist );  // not infile.get(....).  Why not use getline( ) instead?

That's a start.
When you post your revision, please use the and [/code ] tags around your code text, and describe the particular problem you are encountering.

Val[code ] and [/code ] tags around your code text, and describe the particular problem you are encountering.

Val

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.