(iv) Write a function, computePrice that receives two parameters: the first one is a character variable
indicating the size of the pizza (S, M or L) and the second an integer variable indicating the number of
toppings on the pizza. It then computes the cost of the pizza and returns the cost as a floating point
number according to the rules:
• Small pizza = R50 + R5.50 per topping
• Medium pizza = R70 + R6.50 per topping
• Large pizza = R90 + R7.50 per topping
float computePrice(char size, int amountToppings){
switch(size){
case 'S': return 50 + 5.50*amountToppings;
case 'M': return 70 + 6.50*amountToppings;
case 'L': return 90 + 7.50*amountToppings;
}
}
Comments
Leave a comment