There are two deals of an item to buy. The quantities and prices of the item are given below. Write a program in PHP to find the best deal to purchase the item
There are two deals of an item to buy. The quantities and prices of the item are given below. Write a program in PHP to find the best deal to purchase the item
In the above code, better_deal() function takes the four values as arguments and perform the arithmetic and comparison in just three lines of code and it returns the value of a boolean expression. We have embedded the returned boolean value in IF statement and gets the best deal. As we have written the arithmetic and comparison codes within function, so we can use this in multiple places, only we have to change the values and calculations.
Solution
The following code, helps to decide which quantity of item is best to purchase or which deal is fruitful.
Output of the above code
The second deal is best!In the above code, better_deal() function takes the four values as arguments and perform the arithmetic and comparison in just three lines of code and it returns the value of a boolean expression. We have embedded the returned boolean value in IF statement and gets the best deal. As we have written the arithmetic and comparison codes within function, so we can use this in multiple places, only we have to change the values and calculations.
need an explanation for this answer? contact us directly to get an explanation for this answer