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;
		}
	}
}

Recommended Answers

All 2 Replies

What does it mean that they don't look quite right? Are you calling SetPrice and SetTitle one after the other and it's skipping over your SetTitle input?

price < 0.0f isn't right. Have you ever seen a book that costs 0$? :P
You'll have to show us more code.

Btw, those aren't called functions. Those are called methods (the first one is a constructor).

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.