I just wrote a simple program that calculates markup prices by calling user defined functions I created. That part is done, but I need to make a validation check where the user cannot enter in a negative number. I sorta did that using the if statement, but the program needs to repeat until the user enters a valid number. Any help with this? The way I have it set up, if the user enters a negative number, it just stops.
int main()
{
float x = 0.0; // Initialize as 0.
do
{
cout << "Please enter the wholesale cost of an item:" << endl << endl <<"$"; // Move request here
cin x;
if (x <= 0.0)
{
cout << "Invalid number. Please enter a positive cost number." << endl << endl;
}
else
{
cout << endl << "The mark up percentage at 100% is: $" << caculateRetail100 (x) << endl << endl;
cout << endl << "The mark up percentage at 50% is: $" << caculateRetail50 (x) << endl << endl;
}
} while(x<=0.0);