Function Problem, help?

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <iomanip>
double GetWholeSale();
double GetMark();
double CalculateRetail( double, double );
void Report( double );
using namespace std;

void main()
{
	char choice; 
	do
	{
		double catchCost = GetWholeSale();
		double catchMarkup = GetMark();
		void report( );
		cout << "Do you want to do another markup? Enter Y to continue, N to stop: ";
		cin >> choice;
	}
	while ( choice == 'Y');

}
/************** User inputs an item's whole sale************************************/
double GetWholeSale()
{
	int cost;
	cout << " Enter the item's whole sale cost: ";
	cin >> cost;
	while ( cost < 0 )
	{
		cout << "Enter a POSITIVE number for whole sale: ";
		cin >> cost;
	}
	return cost;
}
/************************ User enters mark up**********************/
double GetMark()
{
	double percentage;
	cout << "Enter the item's mark up percentage: ";
	cin >> percentage;
	return percentage;
}
/************************* Calculate and Return retail price*************************/
double CalculateRetail(double percentage , double sale )
{
	double retailmarkup, retail;
	retailmarkup = percentage * sale;
	retail = percentage + sale;
	return retail;
}
/************************* Report the retail price*********************************/
void report ( double retail)
{
	cout << " The retail price is: " << retail << endl; 
}
Last edited on
closed account (zb0S216C)
Here's some advice & hints:

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.

Wazzak
Last edited on
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.
closed account (zb0S216C)
Sunny101 wrote:
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.

Wazzak

Last edited on
Thanks for all your help. Hmmm, how exactly would I tell it to print? Sorry, I'm very knew to this!
in calculate retail you do this:

1
2
3
4
5
6
7
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
}


i would do it like this:

1
2
3
4
double CalculateRetail(double percentage , double sale )
{
	return percentage + sale;
}
Ah, I see. I was supposed to do ' retail = retailmarkup + sale;'

I tried redoing, but am still having loads of trouble on functions. I'll write in my code with what i'm confused on..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <iomanip>
double GetWholeSale();
double GetMark();
double CalculateRetail( double ,double);
void Report();
using namespace 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 only thing showing up in my program is the GetWholeSale() part. It's probably very simple, but I still can't pinpoint what I'm doing wrong.
bump?
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
Topic archived. No new replies allowed.