Answer to Question #8817 in C++ for zane

Question #8817
Write a function calculateItemCost prototyped by

double calculateItemCost(double itemPrice, char discountType, unsigned quantity);

so that the execution of this function will return the price for quantity number of the item priced originally at itemPrice each, and currently discounted according to discountType. For instance, calculateItemCost(10.90, 'D', 2) will return 17.44 because 17.44=10.9*0.8*2. Likewise calculateItemCost(5.50, 'B', 4) will return the value 19.8=5.50*0.9*4.
1
Expert's answer
2012-04-28T09:42:56-0400
double calculateItemCost(double itemPrice, char discountType[], unsigned quantity){

double price;

price = itemPrice*quantity;

if (strcmp(discountType,"A")==0) price *= 0.95;
if (strcmp(discountType,"B")==0) price *= 0.9;
if (strcmp(discountType,"C")==0) price *= 0.85;
if (strcmp(discountType,"D")==0) price *= 0.8;

return price;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS