#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
//*******************************************************************************************************
double getMarkupPercentage();
double getWholeSale();
double calculateRetail(double wholeSaleCost, double markUpPercentage);
void displayRetail(double retailPrice);
//*******************************************************************************************************
int main()
{
string line(40, '*');
double wholeSaleCost,
markUpPercentage,
totalPrice,
retailPrice;
do
{
cout << line << endl;
getWholeSale();
getMarkupPercentage();
calculateRetail(); // Asking for argument
displayRetail(); // Asking for argument
} while (wholeSaleCost = -1);
return 0;
}
double getWholeSale()
{
double wholeSaleCost;
do
{
cout << "Please enter a whole sale price:" << endl;
cout << "(-1 to quit the program): ";
cin >> wholeSaleCost;
if (wholeSaleCost < -1)
{
cout << "INCORRECT: whole sale cannot be less than -1" << endl;
cout << "Please enter a whole sale price:" << endl;
cout << "(-1 to quit the program): ";
cin >> wholeSaleCost;
}
} while (wholeSaleCost < -1);
return wholeSaleCost;
}
double getMarkupPercentage()
{
double markUpPercentage;
do
{
cout << "Please enter a markup percentage: ";
cin >> markUpPercentage;
if (markUpPercentage < 0 || markUpPercentage > 100)
{
cout << "INCORRECT: percentage cannot be less than 0 or more than 100" << endl;
cout << "Please enter a markup percentage: ";
cin >> markUpPercentage;
}
} while (markUpPercentage <= 0);
return markUpPercentage;
}
double calculateRetail(double wholeSaleCost, double markUpPercentage)
{
constdouble RETAIL_PRICE = wholeSaleCost * (100 + markUpPercentage) / 100.0;
return RETAIL_PRICE;
}
void displayRetail(double retailPrice)
{
double wholeSaleCost,
markUpPercentage;
cout << "Retial price will be: " << '$' << fixed << setprecision(2) << calculateRetail() //asking for argument << endl;
}
//I don't really understand what I should be putting within these parameter so this program can work, I tried putting some of the variables within them, but that doesn't work
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
Rather than talking about the whole program check the comments I made:
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std; // <--- Best not to use.
//****************************** Prototypes *************************************************************
double getMarkupPercentage();
double getWholeSale();
double calculateRetail(double wholeSaleCost, double markUpPercentage);
void displayRetail(double retailPrice);
//*******************************************************************************************************
int main()
{
string line(40, '*');
double wholeSaleCost,
markUpPercentage,
totalPrice,
retailPrice;
do
{
cout << line << endl;
wholeSaleCost = getWholeSale(); // <--- These three need to deal with a return value.
getMarkupPercentage();
calculateRetail(wholeSaleCost, markUpPercentage); // Asking for argument. This is the way it should be.
displayRetail(retailPrice); // Asking for argument. This is the way it should be.
} while (wholeSaleCost = -1); // <--- This assigns "-1" to wholeSaleCost. What you want is "==" to compare.
return 0;
}
double getWholeSale()
{
double wholeSaleCost;
do
{
cout << "Please enter a whole sale price:" << endl;
cout << "(-1 to quit the program): ";
cin >> wholeSaleCost;
// <--- Check here for "-1" and return it to main if it is.
if (wholeSaleCost < -1) // <--- This will not work. Even a decimal nmber is greater than zero. This would work better as a while loop. "while (wholeSaleCost <= 0)".
{
cout << "INCORRECT: whole sale cannot be less than -1" << endl;
cout << "Please enter a whole sale price:" << endl;
cout << "(-1 to quit the program): ";
cin >> wholeSaleCost;
// <--- Check here for "-1" and return it to main if it is.
}
} while (wholeSaleCost < -1); // <--- Would work better as less than zero.
return wholeSaleCost;
}
double getMarkupPercentage()
{
double markUpPercentage;
do
{
cout << "Please enter a markup percentage: ";
cin >> markUpPercentage;
if (markUpPercentage < 0 || markUpPercentage > 100) // <--- Again would work better as a while loop.
{
cout << "INCORRECT: percentage cannot be less than 0 or more than 100" << endl;
cout << "Please enter a markup percentage: ";
cin >> markUpPercentage;
}
} while (markUpPercentage <= 0);
return markUpPercentage;
}
double calculateRetail(double wholeSaleCost, double markUpPercentage)
{
constdouble RETAIL_PRICE = wholeSaleCost * (100 + markUpPercentage) / 100.0; // <--- Done well, but this does not need to be a constant.
return RETAIL_PRICE;
}
void displayRetail(double retailPrice)
{
double wholeSaleCost,
markUpPercentage;
//std::cout << std::fixed << std::showpoint << std::setprecision(2);
cout << "Retial price will be: " << '$' << fixed << setprecision(2) << calculateRetail() /*asking for argument*/ << endl; // <--- See comments in main.
}
The first two prototypes need to look like the last two. Not the exact parameters, but the concept. and the function definitions need to match the prototypes. Now in the prototypes only the type of variable needs to be there. As you did in the last two prototypes I like to add the variable names. In my VS IDE this can be a big help when writing the function calls.
The actual function calls only need the variable name that is to be passed to the function. See lines 28 and 29.
In the "calculateRetail" function the variable "RETAIL_PRICE" does not need to be a constant. However it is defined it will be lost when the function ends and goes out of scope.
In the "displayRetail" function the commented line (line 95) I added will work better for you (I have this set up to just click and paste). This line only needs done once, and it could be done in main, and will affect all "cout" statements that follow until something is changed. The "std::showpoint" tells the "cout" to print ".00" should it happen. This helps when aligning the numbers on the screen.
How I will finish the fixes to your program and see if I find anything else.