Problem: The user should be able to specify a field and a value for that field and the program returns all works that match. For example, the user may specify Artist and Smithely, and the program will output all of the information concerning every work in the gallery by that artist.

My problem is being unable to search through the file and output the correct result. this is what i have so far. thank you for your help

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

using namespace std;
const int NUM_PIECES = 120; //represents the max artworks available

enum Medium{OIL, WATERCOLOR, PASTEL, ACRYLIC, PRINT, COLORPHOTO, BLACKANDWHITEPHOTO};
float mediumType[7]; //array of 7 floats, to be indexed by Medium type.
Medium mtype; //variable of the index type

enum Room{MAIN, GREEN, BLUE, NORTH, SOUTH, ENTRY, BALCONY};
float roomType[7]; //array of 7 floats, to be indexed by Room type
Room rtype; //variable of the index type

struct Artwork
{
    string Artist;
    string Title;
    float Price;
    int height;
    int width;
};

//function prototypes
void Openfiles(istream& inData);
void InputNames(string[], ifstream& inData);


int main()
{
    ifstream inData;
    int count[NUM_PIECES];
    string name[NUM_PIECES]; // array of artworks names
    
    inData.open("C:/art.txt");
    if(!inData)
    {
        cout<<"Error: File cannot be opened. Please try again.";
        return 1;
    }

    for ( int artworks = 0; artworks < NUM_PIECES; artworks++) //initializing array
    {
        count[artworks] = 0;
    }

    InputNames(string);

    cin.get(); cin.get();

    return 0;
}

void Openfiles( /* inout*/ ifstream& text)
{
    string inFileName;
    cout << "Enter the name of the file to be processed"<< endl;
    cin >>inFileName;
    text.open(inFileName.c_str());
}

void InputNames(int string[], ifstream& inData)
{
    int strings;
    //zero out the array of counters
    for (int index = 0; index <= 120; index++)
        string[index] = 0;

    inData >> strings;

    while(inData)
    {
        string[strings];
        inData >> strings;
    }
}

Recommended Answers

All 3 Replies

Can you post a quick input example that would be inside of the textfile.

here is the content of the art.txt file:

Artist: Rembrandt
Title : The Hundred Guilder Print
Medium: Watercolor
Size : 40
Width : 75
Room : Entry
Price : 1000000

Artist: Gogh
Title : Starry Night Over the Rhone
Medium: Oil
Size : 60
Width : 85
Room : South
Price : 12000000

Arist : Gogh
Title : Road with Cypress and Star
Medium: Acrylic
Size : 50
Width : 80
Room : Blue
Price : 90000

You are trying to store text from art.txt to an int array. You gave your string[] variable an int type.

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.