Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5. Orders
- Write a method that calculates the total price of an order and prints it on the console. The method should receive one of the following products: coffee, coke, water, snacks; and a quantity of the product. The prices for a single piece of each product are:
- • coffee – 1.50
- • water – 1.00
- • coke – 1.40
- • snacks – 2.00
- Print the result formatted to the second decimal place
- Example
- Input Output
- water
- 5 5.00
- coffee
- 2 3.00
- Hints
- 1. Read the first two lines
- 2. Create a method the pass the two variables in
- 3. Print the result in the method
- using System;
- namespace _05Orders
- {
- class Program
- {
- static void Main(string[] args)
- {
- string product = Console.ReadLine();
- var number = int.Parse(Console.ReadLine());
- PrintOrders(product, number);
- }
- private static void PrintOrders(string product, int number)
- {
- double sumPrice = 0;
- if (product == "coffee")
- {
- sumPrice = 1.50 * number;
- }
- else if (product == "water")
- {
- sumPrice = 1.00 * number;
- }
- else if (product == "coke")
- {
- sumPrice = 1.40 * number;
- }
- else if (product == "snacks")
- {
- sumPrice = 2.00 * number;
- }
- Console.WriteLine($"{sumPrice:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment