I have to code for functions.
1. GetWholeSale() - ask for user's whosale, validate, and return
2. GetMark() - enter markup, validate, and return
3. CalculateRetail() - calculate retail price, return, takes wholesale and markup pass from main // I don't know how to pass from main!
4. Report() - print retail price passed from main. does not return value.
This is what I have. How could I improve/ or fix the program so it runs in accordance to the directions. All I need is alittle guidance!
1) Initialise variables, like so: int My_int(0). It reduces the likelihood of bugs.
2) In GetMark(), you instructions say that you must validate your mark up - you do no such thing.
3) It seems you must do this:
CalculateRetail(GetWholeSale(), GetMark());
In this code, the value returned from ::GetWholeSale() is placed within ::CalculateRetail()'s percentage parameter. The value returned from ::GetMark() is placed within ::CalculateRetail()'s sale parameter.
I implemented this, however the catchMarkup function does not display in the program.
Functions seem so easy, but as soon as I try them my brain goes ahfkjldasdjk.
I implemented this, however the catchMarkup function does not display in the program.
There's no function called catchMarkup(). Did you mean the catchMarkup variable in main()? By the way, it should be int main(), not void main(). If you did mean the variable, it's because you never told it to print.
double CalculateRetail(double percentage , double sale )
{
double retailmarkup, retail; //what does retailmarkup do?
retailmarkup = percentage * sale; //you set it then do nothing with it
retail = percentage + sale; //you can initialize this when you declare the variable
return retail; //why dont you just return percentage + sale
}
#include <iostream>
#include <iomanip>
double GetWholeSale();
double GetMark();
double CalculateRetail( double ,double);
void Report();
usingnamespace std;
int main() // If i use int instead of void, don't I have to have a return function? My professor usually uses void..
{
char choice;
do
{
double WholeSale = GetWholeSale(); // How do I make sure these show up? Am I calling them right?
double getMark = GetMark();
double catchretail = CalculateRetail( WholeSale , getMark); // Am i doing this right?
Report ();
cout << " Do you want to do another markup? Y for yes and N for no: ";
cin >> choice;
}
while( choice == 'y' );
}
/************** Print Retail Price *********************/
// For this, I am supposed to print the retail price passed from main, what does that mean?
void Report (double retailprice)
{
cout << "The retail price is " << retailprice << endl;
}
/*********** Calculate Retail Price *******************/
// For this, I am supposed to take the whole sale and markup passed from main. How would I do that?
double CalculateRetail( double wholesale, double markup)
{
double retailprice = (wholesale*markup) + wholesale;
return retailprice;
}
/********* Input item's wholesale***********/
double GetWholeSale()
{
double wholesale;
cout << "Enter the item's wholesale cost: ";
cin >> wholesale;
while ( wholesale < 0 )
{
cout << "Enter a positive number for wholesale: ";
cin >> wholesale;
}
return wholesale;
}
/********** Input item's markup ************/
double GetMark()
{
double markup;
cout << " Enter the item's markup percentage: ";
cin >> markup;
while ( markup < 0 )
{
cout << "Enter a positive number for markup: ";
cin >> markup;
}
return markup;
}
The first problem is that line 6 and 29 don't match. Line 6 must be like line 29.
You pass catchretail to Report(). Everything above Report() is ok.
In GetMark() you ask the user to enter percentage. What do you expect the user to enter?
I'd enter 50 when I mean 50 precent. But then your calculation is wrong. You need to devide it by 100