I am trying to write a program that asks for the wholesale cost of an item and its markup percentage, and displays the retail price.
Well, I did that the regular way, but...

My instructions require for me to:
*Create a function that accepts the wholesale cost and markup percentage as arguments
*Returns the retail price of the item
*Do not accept negative values for either the wholesale cost of the item or the percent markup.

I have read my book, but I have no idea how to create a function for wholesaleCost and markupPrice. I tried, but I got an error.
Here is my regular program (without the user-defined function):

#include <iostream>
#include <iomanip>
#include <conio>
using namespace std;
int main()
        double wholesaleCost, markupPercentage, markupAmount, retailPrice;
        cout << "What is the wholesale cost of the item? ";
        cin  >> wholesaleCost;
        cout << "What is the markup percetage for this item? ";
        cin  >> markupPercentage;
        markupAmount = wholesaleCost * markupPercentage;
        retailPrice = wholesaleCost + markupAmount;
        cout << fixed << showpoint <<setprecision(2);
        cout << "Your retail price for this item is $" <<retailPrice <<endl;
        return 0;

Does anyone have any idea how I can do this?? Any input is appreciated.

10 Years
Discussion Span
Last Post by thekashyap
usingnamespace std;
double CalculateMarkUpAmount(double, double);
double CalculateRetailPrice(double, double);
int main()

{[INDENT]double wholesaleCost, markupPercentage, markupAmount, retailPrice;[/INDENT]

[INDENT]cout << "What is the wholesale cost of the item? ";[/INDENT][INDENT]cin >> wholesaleCost;[/INDENT]

[INDENT]cout << "What is the markup percetage for this item? ";[/INDENT][INDENT]cin >> markupPercentage;[/INDENT]

[INDENT]markupAmount = CalculateMarkUpAmount(wholesaleCost, markupPercentage);[/INDENT]

[INDENT]retailPrice = CalculateRetailPrice(wholesaleCost, markupAmount);[/INDENT]

[INDENT]cout << fixed << showpoint <<setprecision(2);[/INDENT]

[INDENT]cout << "Your retail price for this item is $" <<retailPrice <<endl;[/INDENT]


[INDENT]return 0;[/INDENT]}
double CalculateMarkUpAmount(double wholeSale, double markUpPercent)

{[INDENT]return wholeSale * markUpPercent;[/INDENT]}
double CalculateRetailPrice(double wholeSale, double markUpAmount)

{[INDENT]return wholeSale + markUpAmount;[/INDENT]}

So take a look at what I did, and compare that to the long long long tutorial i wrote on how to use functions in your other post.


Don't forget to check for negative part..
You'll need to change the return type probably or throw an exception, if you already know how to..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.