I'm a student (almost finished with my semester) and I'm having a problem using an if statement to compare a value in an array. The book I'm using lacks specific information on 2-dimensional character arrays so I'm turning to this board as a source for help. The assignment is to create a program using class inheritance (which I'm not sure I did correctly but I'm not getting errors and it appears to be functioning the way I want). The only problem is that when I try to determine if the user enters a famous artist, the program will not assign a 25000 value to the amount field. Any suggestions?
Code:
// Assignment:
// Create a Painting class that holds the painting title, artist name, and value.
// All paintings are valued at $400 unless they are FamousPaintings. The FamousPainting
// subclass overrides the Painting value and sets each Painting's value to $25,000.
// Write a main() function that declares an array of 10 Painting objects. Prompt the
// user to enter the title and artist for each of the 10 paintings. Consider the
// Painting to be a FamousPainting, if the artist is one of the following: Degas,
// Monet, Picasso or Rembrandt. Display the 10 paintings.
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Painting
{
private:
char title[30],
painter[20];
double value;
public:
void setData(char paintingName[], char paintingArtist[]);
void outputData();
};
class FamousPainter:public Painting
{
private:
double price;
public:
void showData();
};
void Painting::setData(char paintingName[], char paintingArtist[])
{
double price = 400.00;
strcpy(title, paintingName);
strcpy(painter, paintingArtist);
}
void Painting::outputData()
{
cout<<" This painting is worth $400.00"<<endl;
}
void FamousPainter::showData()
{
cout<<"This painting is worth $25,000.00"<<endl;
}
void main()
{
char name[10][30];
char artist[10][20];
int x;
Painting paint;
FamousPainter amount;
for(x=0; x<10; ++x)
{
cout<<"Enter title of painting: ";
cin>>name[x];
cout<<"Enter the artist of painting: ";
cin>>artist[x];
}
for(x=0; x<10; ++x)
{
cout<<name[x]<<" "<<artist[x];
if(*artist == "Degas" ||*artist == "Monet" ||
*artist == "Picasso"||*artist == "Rembrandt")
amount.showData();
else
paint.outputData();
}
paint.setData(name[x], artist[x]);
getch();
}
p.s. Read the message on the code tags...hope this is okay
Thanks!
Judy