Answer to Question #342894 in C++ for Padi

Question #342894

(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


1
Expert's answer
2022-05-26T09:14:48-0400
#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;
}

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
New on Blog
APPROVED BY CLIENTS