| | |
User-defined functions
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi.
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):
Does anyone have any idea how I can do this?? Any input is appreciated.
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):
C++ Syntax (Toggle Plain Text)
#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; getch(); return 0; }
Does anyone have any idea how I can do this?? Any input is appreciated.
If you feed a man a fish, you feed him for a day.
If you teach a man to fish, you feed him for a lifetime.
If you teach a man to fish, you feed him for a lifetime.
•
•
Join Date: Apr 2007
Posts: 103
Reputation:
Solved Threads: 17
#include<iostream> usingnamespace std; #include<iomanip> double CalculateMarkUpAmount(double, double); double CalculateRetailPrice(double, double); 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 = CalculateMarkUpAmount(wholesaleCost, markupPercentage);retailPrice = CalculateRetailPrice(wholesaleCost, markupAmount);cout << fixed << showpoint <<setprecision(2);cout << "Your retail price for this item is $" <<retailPrice <<endl;cin.get();return 0;} double CalculateMarkUpAmount(double wholeSale, double markUpPercent) {return wholeSale * markUpPercent;} double CalculateRetailPrice(double wholeSale, double markUpAmount) {return wholeSale + markUpAmount;}
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.
Last edited by mariocatch; Apr 10th, 2007 at 2:35 pm.
![]() |
Similar Threads
- User-Defined Function - part 2 (C++)
- help:stl vector of user defined objects (C)
- accessing common user-defined functions (ASP.NET)
- error in user defined string class (C++)
- using(STL)function object (bind2nd) with a user defined function object (C++)
- DECLARATION SYNTAX ERROR (for bc 31 user) (C++)
- User defined functions (C++)
Other Threads in the C++ Forum
- Previous Thread: read all files in a directory
- Next Thread: Multiple definition error
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





