SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Barbara Dolye
Chapter:
Data Types And Expressions
Exercise:
Programming Exercises
Question:4 | ISBN:9781285096261 | Edition: 4

Question

Write a program that shows the formatted retail price of items when there is a 15% markup. Test the program by performing a compile-time initialization with Ruggy Shoes, which has a wholesale price of $52.00. Display appropriately labeled retail and wholesale values for the shoes. Once you get that running, go back into your source code, add lines of code that will reassign the memory location’s values for a Teno Jacket, which has a wholesale price of $71.00. Add additional lines of code, which will display the new information.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Explanation:

  • The following code is used to show the formatted retail price of items, when the item is in 15% mark-up.
  • In this program the value 0.15 is multiplied by whole sale price to get the 15% of the whole sale price.
  • If 15 percentage of whole sale price is added with the whole sale price then the Retail price will be display.
  • The method string.Format("{0:0.00}",variableNmae) is used to format the decimal number up to two decimal places.
     

Program:

// Create a class named FormatedRetailPrice
class FormatedRetailPrice
{
	// Create a main method to run the program
	static void Main(string[] args)
	{
		// Declare a string variable named itemName to store the item name
		string itemName = "Ruggy Shoes";
		// Declare a double variable named wholeSalePrice to store the whole sale price.
		double wholeSalePrice = 52.00;			

		// Display item name
		Console.WriteLine("Item: " + itemName);
		// Display whole sale price
		Console.WriteLine("Whole Sale Price: " + string.Format("{0:0.00}", wholeSalePrice));
		// Display retail price.
		Console.WriteLine("RetailPrice: " + string.Format("{0:0.00}", (wholeSalePrice + (wholeSalePrice * 0.15)))); 

		// The following lines of code is used to reassign the
		// memory location vlaues for a Teno Jacket.
		itemName = "Teno Jacket";
		wholeSalePrice = 71.50;

		Console.WriteLine();
		// Display item name
		Console.WriteLine("Item: " + itemName);
		// Display whole sale price
		Console.WriteLine("Whole Sale Price: " + string.Format("{0:0.00}", wholeSalePrice));
		// Display retail price.
		Console.WriteLine("RetailPrice: " + string.Format("{0:0.00}", (wholeSalePrice + (wholeSalePrice * 0.15))));

		Console.ReadKey();
	}
}

 

Output:

Item: Ruggy Shoes
Whole Sale Price: 52.00
RetailPrice: 59.80

Item: Teno Jacket
Whole Sale Price: 71.50
RetailPrice: 82.23

 

0 0

Discussions

Post the discussion to improve the above solution.