Saturday 4 August 2018

Discount

QUESTION DESCRIPTION


Mr. Phileas Fogg is a very perfect man. He saves money even on petty things. One day he heard a discount offer announced in a mall. He wants to purchase lot of items to save his money. The discount is given only when atleast two items are bought. Since each item has different discount prices, he finds it difficult to check the amount he has saved. So he approaches you to device an automated discount calculator to make him easy while billing.

I/O Constraints :  The input consists of two floating point values denoting price of item1 and item2. The third value denotes the discount value in %. The output consists of three floating point values denoting the total amount, discounted price and the amount saved.

Note: Correct the floating point decimals to 2 places.

TEST CASE 1

INPUT

20.50
45.40
10

OUTPUT

Total amount:$65.90
Discounted amount:$59.31
Saved amount:$6.59 

EXPLANATION :

The question simply requests you to accept 3 values (float) and perform trivial operations on them. This is a basic percentage question where you ought to find the discount value of all the items bought by the customer.

Note: The note at the end of the question simply wants the answer correct upto 2 decimal places i.e. 2.567 will result in 2.57 as the answer, this can be easily done using the printf function to print the values


ALGORITHM :

This is a simple algorithm:

Steps :
  •  Take 3 numbers as input (3 float numbers a,b,c)
  •  Print the addition of the first two numbers after the Total amount value
  •  Then calculate the discount value by multiplying the sum by discount/100 as the discount is in percentage.
  • Subtract the discount from the sum and print it as the Discounted amount 
  • Print the discount value as the Saved amount.
  • Exit


Note: Please mind the spaces, the : and the $ symbol

Note 2: Check this link  to understand how printf flags work. To print at most 2 decimal values use the %0.2f flag, here % stands for flag identifier, 0.2 states at max 2 decimal values while the rest will be rounded off and f is the flag for printing the value of float.


SOLUTION :  (Please use this as reference only)




Link to Code : Discount
(Please Try To Refrain From Copying The Code)

No comments:

Post a Comment