Description: This function applies discount percentage on an item price unless t
ID: 3679869 • Letter: D
Question
Description: This function applies discount percentage on an item price unless the item price is less than the whole sale price. For example, a product at $10 with a wholesale price of $5 and a discount of 10% returns $9.
function applyDiscount(productPrice : Double,
wholesalePrice : Double,
discount : Double)
Return Double
Create variable discountedPrice as double
discountedPrice = productPrice * (1 – discount)
if (discountedPrice < wholesalePrice)
discountedPrice = wholesalePrice
end if
return discountedPrice
End function
Explanation / Answer
#include<iostream>
using namespace std;
double applyDiscount(double productPrice, double wholesalePrice, double discount ){
double discountedPrice;
discountedPrice = productPrice * (1 - discount);
if (discountedPrice < wholesalePrice){
discountedPrice = wholesalePrice;
}
return discountedPrice;
}
int main(){
double price = applyDiscount(10, 5, 10);
cout<<"Producr price: $"<<price<<endl;
return 0;
}
/*
Output:
Producr price: $5
*/