Reference Parameters?

C++ Program causing confusion

Page 1 of 1

6 Replies - 926 Views - Last Post: 23 February 2009 - 08:05 PM Rate Topic: -----

#1 Funkshunn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 18-February 09

Reference Parameters?

Posted 23 February 2009 - 06:40 PM

 #include<iostream>
#include<iomanip>

using namespace std;

int main(){
	cout << "What is the wholesale price of the item? ";
	double itemPrice;
	cin >> itemPrice;

	cout << "What is the expected number of days until the item is sold? ";
	int daysUntilSold;
	cin >> daysUntilSold;

	assert(daysUntilSold <= 7);
	double lowMarkup = itemPrice + (itemPrice * .05);
	cout << fixed << setprecision(2);
	cout << "Retail price of the item is $" << lowMarkup << endl;
}


This program almost does what it is supposed to do.

I was given an assignment and this is exactly what it says:

- You have been commissioned by a supermarket chain to write a program that will determine the retail price of an item given suitable input.
- Their pricing is as follows:
- Any item that is expected to be sold in a week is marked up 5%
- Any item that is expected to stay on the shelf for more than 1 week is marked up by 10%
- (This, in a nutshell, means that before 7 days the cost of the item is 5% more than wholesale, and after 7 days it's 10% more.)

- Input -- Whole sale prie of an item (Completed)
-- Expected number of days until the item is sold (Completed)
- Output -- The retail price of the item (Completed)



Here is what I don't understand: Use call-by-reference parameters for input.

Help plz!

Is This A Good Question/Topic? 0
  • +

Replies To: Reference Parameters?

#2 bsaunders   User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Reference Parameters?

Posted 23 February 2009 - 06:53 PM

The instructor wants you to implement the calculation of the retail price in a seperate function.

You can try creating a function called getRetailPrice that calculates the retail price of the item.

The function should take an argument for each input variable (wholesale price, number of days until item is sold), and return the output (retail price).

Try that, and post it here.

This post has been edited by bsaunders: 23 February 2009 - 06:58 PM

Was This Post Helpful? 0
  • +
  • -

#3 Funkshunn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 18-February 09

Re: Reference Parameters?

Posted 23 February 2009 - 07:05 PM

#include<iostream>
#include<iomanip>

using namespace std;

double lowMarkup;
void retailPrice(double itemPrice, int daysUntilSold)
{
	cout << "What is the wholesale price of the item? ";
	cin >> itemPrice;

	cout << "What is the expected number of days until the item is sold? ";
	cin >> daysUntilSold;

	assert(daysUntilSold <= 7);
	lowMarkup = itemPrice + (itemPrice * .05);
}

int main(){

	retailPrice(WHAT GOES HERE??);

	cout << fixed << setprecision(2);
	cout << "Retail price of the item is $" << lowMarkup << endl;
}
 



Am I on the right track??
Was This Post Helpful? 0
  • +
  • -

#4 bsaunders   User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Reference Parameters?

Posted 23 February 2009 - 07:12 PM

The function should look something like this:

double getRetailPrice(double &wholesalePrice, int &daysUntilSold)
{
	double retailPrice = 0.0;

	if(daysUntilSold <= 7)
		retailPrice = wholesalePrice + (wholesalePrice * 0.05);
	else if(daysUntilSold > 7)
		retailPrice = wholesalePrice + (wholesalePrice * 0.10);

	return retailPrice;
}

This post has been edited by bsaunders: 23 February 2009 - 07:13 PM

Was This Post Helpful? 0
  • +
  • -

#5 Funkshunn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 18-February 09

Re: Reference Parameters?

Posted 23 February 2009 - 07:26 PM

#include<iostream>
#include<iomanip>

using namespace std;


double getRetailPrice(double& wholesalePrice, int& daysUntilSold)
{
	double retailPrice = 0.0;

	if(daysUntilSold <= 7)
		retailPrice = wholesalePrice + (wholesalePrice * 0.05);
	else
		retailPrice = wholesalePrice + (wholesalePrice * 0.10);

	return retailPrice;
}

int main(){

	retailPrice(???);

	cout << fixed << setprecision(2);
	cout << "Retail price of the item is $" << retailPrice << endl;
} 



What needs to go inside the retailPrice() under the main()?
Was This Post Helpful? 0
  • +
  • -

#6 bsaunders   User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Reference Parameters?

Posted 23 February 2009 - 07:30 PM

What is retailPrice()?
Was This Post Helpful? 0
  • +
  • -

#7 OrganizedChaos   User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 153
  • Joined: 29-November 08

Re: Reference Parameters?

Posted 23 February 2009 - 08:05 PM

//User input of the price of the item
//User input of the days until sold
cout << "Retail price of the item is: $" << retailPrice(itemPrice, daysUntilSold) << endl; 

is probably what you want in main()
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1