'Having trouble with getting C++ program to run correctly
I am still fairly new to programming so my code is in no way perfect. I am having trouble getting my program to run correctly and I am honestly suck on what needs to be fixed, although I do know the ReadArtGalleryData part is not written correctly. I have attached a picture of what the output is supposed to look like. Any help is greatly appreciated!
#include <iostream>
#include <fstream>
using namespace std;
// global variables
struct ARTWORK
{
string Name; // artist name
string Title; // painting title
string Medium; // material used
string Room; // name of room its held in
double Price; // price of painting
double Height; // height of painting
double Width; // width of painting
};
const int NUMPIECES = 50;
ARTWORK GalleryOfArt[NUMPIECES]; // an array GalleryOfArt of structs ArtWork, of size 50
int ReadArtGalleryData(); // reads in the gallery inventory for each painting from the file SimpleArtGalleyDimen.txt
int PrintMenu(); // displays a menu of different search fields by which the user can search the gallery
void PrintEntry(int); // function to print details of art found in the gallery
void ActionOnChoice(int choice, int count); // branching function depending on the choice made by the user
void FindString(int count, int choice, string searchStr); // function used to search the gallery inventory using the following fields - artist name, painting title, medium used, room displayed in
void FindNumber(int choice, float searchNumber); // function used to search the gallery inventory using either the price, height, width, or value
int main()
{
int fileread = ReadArtGalleryData();
int choice = PrintMenu();
ActionOnChoice(choice, fileread);
return 0;
}
int ReadArtGalleryData()
{
int i = 0;
fstream infile;
infile.open("SimpleArtGalleryDimen.txt");
}
int PrintMenu()
{
int fileread;
cout << "1. Print Entry" << endl;
cout << "2. Find String" << endl;
cout << "3. Find Number" << endl;
cin >> fileread;
return fileread;
}
void PrintEntry(int fileread)
{
for(int i = 0; i < fileread; i++)
{
cout << setw(15);
cout << GalleryOfArt[i].Name << endl;
cout << setw(15);
cout << GalleryOfArt[i].Title << endl;
cout << setw(15);
cout << GalleryOfArt[i].Medium << endl;
cout << setw(15);
cout << GalleryOfArt[i].Room << endl;
cout << setw(15);
cout << GalleryOfArt[i].Price << endl;
cout << setw(15);
cout << GalleryOfArt[i].Height << endl;
cout << setw(15);
cout << GalleryOfArt[i].Width << endl;
}
}
void ActionOnChoice(int choice, int count)
{
if(choice == 1)
{
PrintEntry(count);
}
else if(choice == 2)
{
int x;
string searchStr;
cin >> x >> searchStr;
FindString(count, x, searchStr);
}
else if(choice == 3)
{
int x;
float info;
cin >> x >> info;
FindNumber(x, info);
}
}
void FindString(int count, int choice, string searchStr)
{
for(int i = 0; i < count; i++)
{
if(choice == 1)
{
if(GalleryOfArt[i].Name == searchStr)
{
cout << "String in index: " << i << endl;
}
}
else if(choice == 2)
{
if(GalleryOfArt[i].Title == searchStr)
{
cout << "String in index: " << i << endl;
}
}
else if(choice == 3)
{
if(GalleryOfArt[i].Medium == searchStr)
{
cout << "String in index: " << i << endl;
}
}
}
}
void FindNumber(int choice, float searchNumber)
{
for(int i = 0; i < NUMPIECES; i++)
{
if(choice == 1)
{
if(GalleryOfArt[i].Price == searchNumber)
{
cout << "Number in index: " << i << endl;
}
}
else if(choice == 2)
{
if(GalleryOfArt[i].Width == searchNumber)
{
cout << "Number in index: " << i << endl;
}
}
else if(choice == 3)
{
if(GalleryOfArt[i].Height == searchNumber)
{
cout << "Number in index: " << i << endl;
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
