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. Input Validation: Do not accept negative values for either the wholesale cost of the item or the markup percentage.
Solutions
Verified#include <iostream>
#include <iomanip> //include iomanip library for precision commands
using namespace std;
//function prototype
double calculateRetail(double, double);
int main(){
//declare variables to store user input
double wholesale, markup;
//prompt user to enter values
//and read from keyboard
cout << "Please enter wholesale price:\n";
cin >> wholesale;
cout << "Please enter markup percentage:\n";
cin >> markup;
//validate input
if(wholesale >= 0 && markup >= 0){
//format output
cout << fixed << setprecision(2) << endl;
//display final message and call function
//with the data read as arguments
cout << "The retail price is: $" << calculateRetail(wholesale, markup) << ".\n";
}
else{
//print error message
cout << "Please run program again and use only ";
cout << "positive values!\n";
}
return 0;
}
double calculateRetail(double wholesalePrice, double markupPercent){
return (wholesalePrice + (wholesalePrice * markupPercent));
}
#include
float calculateRetail(int,float);
int main() { int cost = 0; float markUp = 0;
cout << "Enter in the cost of the item:\n";
cin >> cost;
//Check if the cost is negative, if so loop until the user inputs a positive value.
while(cost < 0)
{
cout << "Cost cannot be a negative value. Please enter a positive value:";
cin >> cost;
}
cout << "\nEnter the markup percentage %:\n";
cin >> markUp; // Input a number between 0 and 100.
//Check if the markUp is negative, if so loop until the user inputs a correct value
while(markUp < 0)
{
cout << "The markup cannot be less than 0, please enter a positive value: ";
cin >> markUp;
}
markUp = markUp/100; // Divide it by 100 to get the percentage
cout<< "\nThe Retail Price is: " << calculateRetail(cost, markUp);
}
float calculateRetail(int cost, float markUp)
{
return (cost + cost*markUp);
}
Create an account to view solutions
Create an account to view solutions
Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th EditionDavid A. Patterson, John L. Hennessy
Starting Out with C++ from Control Structures to Objects
8th EditionGodfrey Muganda, Judy Walters, Tony Gaddis
