(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
#include <iostream>
using namespace std;
float computePrice(char size, int numberToppings){
float cost;
switch(size){
case 'S':
cost = 50 + 5.50*numberToppings ;
break;
case 'M':
cost = 70 + 6.50*numberToppings;
break;
case 'L':
cost = 90 + 7.50*numberToppings;
break;
default:
cost = 0;
}
return cost;
}
int main() {
char size;
int n;
cout<<"Enter the size of the pizza (S, M or L): ";
cin>>size;
cout<<"Enter the number of toppings on the pizza: ";
cin>>n;
cout<<"The cost of the pizza ";
cout<<computePrice(size, n);
cout<<endl;
return 0;
}
Comments
Leave a comment