Hello everyone. I'm teaching myself C++ and I've found this lesson online on passing pointers. I've got most of it down, but two of the functions for the program aren't displaying right. Would you wise (experienced) ones have a moment to look at just these functions? Are they looking wrong to you?
Here's the code:
// Still need to initialize Name
Books::Books() : Price(0.0f), Type( "Presentation" )
{
}
// Helper functions to do the work of getting, validating, and displaying the user data.
// This will allow good reuse in future functions.
void Books::SetTitle()
{
cout << "Enter Title:" << endl;
getline (cin, Title);
}
// Needs validation since its a float.
// This will keep the user in the input phase until they enter a valid value for 'price'.
void Books::SetPrice()
{
do
{
cout << "\n Enter Book Price:";
cin >> price;
cout << "Price accepted\n";
}
while (price < 0.0f);
{
cout << "\n Invalid Price." << endl;
}
}
// Tricky mutator - have to check it against Each type listed
void Books::SetType()
{
while (true)
{
cout << "\n Enter Type:" << endl;
cin >> Type;
if (Type != "Biography" && Type != "Fiction" && Type !="History" && Type !="Children's" && Type !="" && Type !="Textbook")
{
cout << "Invalid Type.\n" << endl;
}
else
{
break;
}
}
}