Hello, I want to know if somebody can help me in my code. My code is about create a class named RealState that has data members to hold the price, bedrooms and baths of a house. Write a main() function that instanties a RealState object, allows the user to enter the data and display the data members. The user should recieve an appropiate thrown eror message if negative values are entered for any of the data members.
My problem is when i used the TRY Block to compare and throw the values. All comments or sugerents are welcome. Thanks all!!!!
CODE
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
class RealState
{
private:
double HousePrice;
int BedRooms;
int Baths;
public:
int dataEntry();
void showdata();
};
int RealState::dataEntry()
{
cout<<"PLEASE ENTER A PRICE OF A HOUSE: ";
cin>>HousePrice;
cout<<"NOW, ENTER THE NUMBER OF BEDTROOMS: ";
cin>>BedRooms;
cout<<"FINALLY, ENTER HOW MANY BATHS ARE: ";
cin>>Baths;
if (HousePrice<0 || BedRooms<0 || Baths<0)
throw("*****!!INVALID ENTRY!!*****");
return(HousePrice);//I dont know If this is correct(3return values)
return(BedRooms);
return(Baths);
}
void RealState::showdata()
{
cout<<"\n********************"<<endl;
cout<<"HOUSE PRICE: "<<HousePrice<<endl;
cout<<"# OF BEDROOMS: "<<BedRooms<<endl;
cout<<"# OF BATHS: "<<Baths<<endl;
cin.get();
}
void main()
{
int value;
RealState HouseValue;
HouseValue.dataEntry();
try
{
value=RealState::dataEntry();//Here is wher I try to call a function to examined.
}
catch(const char msg[])
{
cout<<"^^^FATAL ERROR^^^"<<endl;
cout<<msg<<endl;
}
HouseValue.showdata();
cin.get();
}