Question

Pizza Hub sells pizzas of four sizes, S, M, L, X. The prices are $6.99, $8.99,...

Pizza Hub sells pizzas of four sizes, S, M, L, X. The prices are $6.99, $8.99, $12.50, and $15.00 respectively. For each pizza, there is an optional extra topping that costs $1.00, $2.00, $3.25, and $4.50 for each size. Write a program to prompt a user to order one pizza of any size, and then ask if an extra topping is needed. Based on these, calculate and display the cost of the ordered pizza accordingly. For this program, you need to use three parallel arrays to hold the sizes, prices, the topping costs, and you can use predefined array methods if needed.
Please Write this program in C#

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
class HelloWorld {
static void Main() {
char[] sizes={'S','M','L','X'}; //sizes array
double[] prices={6.99,8.99,12.50,15.00}; //prices array
double[] topping={1.00,2.00,3.25,4.50}; //topping array
  
char size_choice,topping_choice;
double total_cost=0.0;
Console.Write("Enter the size of the pizza(S,M,L,X): ");
size_choice=char.Parse(Console.ReadLine()); //inputting the size of pizza
Console.Write("Do you want topping(Y/N): ");
topping_choice=char.Parse(Console.ReadLine()); //inputting whether the customer wants toppings or not
  
for(int i=0;i<sizes.Length;i++){
if(size_choice==sizes[i]){ //checking the size_match
total_cost+=prices[i]; //adding the cost of the matched size
if(topping_choice=='Y'){ //if topping is choosen then
total_cost+=topping[i]; //add the cost of topping to the total cost
}
break;
}
}
Console.Write("Total cost: $"+total_cost); //print the cost
}
}

14. 9 using System; 10 - class HelloWorld { 11 - static void Main() { 12 char[] sizes={ S, M, L,X}; //sizes array 13

Add a comment
Know the answer?
Add Answer to:
Pizza Hub sells pizzas of four sizes, S, M, L, X. The prices are $6.99, $8.99,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT