Question

# 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
Step 1
1 of 2
#include <iostream>#include <iomanip>  //include iomanip library for precision commandsusing namespace std;//function prototypedouble 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));}

## Recommended textbook solutions

#### Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionDavid A. Patterson, John L. Hennessy
220 solutions

#### Starting Out with C++ from Control Structures to Objects

8th EditionGodfrey Muganda, Judy Walters, Tony Gaddis
1,294 solutions

#### Fundamentals of Database Systems

7th EditionRamez Elmasri, Shamkant B. Navathe
687 solutions

#### Introduction to Algorithms

3rd EditionCharles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
726 solutions