Write a program that asks the user to enter an item's wholesale cost and its markup
percentage. It should then display the item's retail price. For example:
* If an item's wholesale cost is 5.00 and its markup percentage is 100%. then
the item's retail price is 10.00.
* If an item's wholesale cost is 5.00 and its markup percentage is 50%. then
the item's retail price is 7.50.
The program should have a function named calculateRetail that receives the wholesale
cost and the markup percentage as arguments, and returns the retail price of the item.
SAMPLE RUN OUTPUT
Enter the item's wholesale cost: 8.00
Enter the item's markup percentage (e.g. 15.0): 30
The retail price is $10.40
----------------------------
When I run the program from the sample run output I get $248 instead of $10.40 and I'm confused as to what I'm doing wrong. Any help is appreciated.
Here is what I have so far:
#include
#include
using namespace std;
// function prototype
double calculateRetail();
int main()
{
double RetalPrice;
cout << "This program calculates and displays the retail price of an item.\n";
RetalPrice = calculateRetail();
cout << fixed << showpoint << setprecision(2);
cout << "The retail price of the item is $" << RetalPrice <<endl;
return 0;
}
double calculateRetail()
{
double Cost,
Markup;
do
{
cout << "What is the item's wholesale cost? ";
cin >> Cost;
if (Cost < 0)
{
cout << "Error!\n"
<< "Wholesale cost must be a positive number.\n";
}
} while (!(Cost > 0));
do
{
cout << "What is the item's markup percentage? ";
cin >> Markup;
if (Markup < 0)
{
cout << "Error!\n"
<< "The markup percentage must be a positive number.\n";
}
} while (!(Markup > 0));
#include <iostream>
#include <iomanip>
usingnamespace std;
// function prototype
double calculateRetail();
int main()
{
cout << "This program calculates and displays the retail price of an item.\n";
constauto RetalPrice {calculateRetail()};
cout << fixed << showpoint << setprecision(2);
cout << "The retail price of the item is $" << RetalPrice << '\n';
}
double calculateRetail()
{
double Cost {}, Markup {};
do {
cout << "What is the item's wholesale cost? ";
cin >> Cost;
} while ((Cost <= 0) && (cout << "Error! Wholesale cost must be a positive number.\n"));
do {
cout << "What is the item's markup percentage? ";
cin >> Markup;
} while ((Markup <= 0) && (cout << "Error! The markup percentage must be a positive number.\n"));
return Cost * (1.0 + (Markup / 100.0));
}