Loading...
+ Нов въпрос
parosaG avatar parosaG 0 Точки

03. Vacation 91/100

Здравейте в тази задача не мога да си намеря грешката. Може ли някой да ми помогне?

Това е линк към кода ми: https://pastebin.com/H5uL30JC

Условието на задачата:

You will receive three lines from the console:

  • A count of people who are going on vacation.
  • Type of the group (Students, Business or Regular).
  • The day of the week which the group will stay on (Friday, Saturday or Sunday).

Based on the given information calculate how much the group will pay for the entire vacation.

The price for a single person is as follows:

 

Friday

Saturday

Sunday

Students

8.45

9.80

10.46

Business

10.90

15.60

16

Regular

15

20

22.50

There are also discounts based on some conditions:

  • Students – if the group is 30 or more people, you should reduce the total price by 15%.
  • Business – if the group is 100 or more people, 10 of the people stay for free.
  • Regular – if the group is between 10 and 20  people (both inclusively), reduce the total price by 5%.

Note: You should reduce the prices in that EXACT order!

As an output print the final price which the group is going to pay in the format:

"Total price: {price}"

The price should be formatted to the second decimal point.

Examples

Input

Output

30

Students

Sunday

Total price: 266.73

40

Regular

Saturday

Total price: 800.00

Тагове:
0
Programming Fundamentals
Axiomatik avatar Axiomatik 2178 Точки

Some minor issues with the code, but the main error =>

  • Business – if the group is 100 or more people, 10 of the people stay for free.

10 people stay for free, but that does not imply a de facto 10% percent discount.

;-)

Code:

using System;
 
namespace _03._Vacation
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int cntPeople = int.Parse(Console.ReadLine());
            string typeGroup = Console.ReadLine();
            string day = Console.ReadLine();
            double price = 0.0;
            double pricePerPerson = 0.0;

            if (typeGroup == "Students")
            {
                if (day == "Friday")
                {
                    pricePerPerson = 8.45;

                    if (cntPeople >= 30)
                    {
                        price = (cntPeople * pricePerPerson);
                        price = price - (price * 0.15);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
                else if (day == "Saturday")
                {
                    pricePerPerson = 9.80;

                    if (cntPeople >= 30)
                    {
                        price = (cntPeople * pricePerPerson);
                        price = price - (price * 0.15);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
                else if (day == "Sunday")
                {
                    pricePerPerson = 10.46;

                    if (cntPeople >= 30)
                    {
                        price = (cntPeople * pricePerPerson);
                        price = price - (price * 0.15);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
            }
            else if (typeGroup == "Business")
            {
                if (day == "Friday")
                {
                    pricePerPerson = 10.90;

                    if (cntPeople >= 100)
                    {
                        // price = (cntPeople * pricePerPerson);
                        // price = price - (price * 0.1);
                        // Not 10% !!!

                        cntPeople -= 10;
                        price = (cntPeople * pricePerPerson);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
                else if (day == "Saturday")
                {
                    pricePerPerson = 15.60;

                    if (cntPeople >= 100)
                    {
                        // price = (cntPeople * pricePerPerson);
                        // price = price - (price * 0.1);
                        // Not 10% !!!

                        cntPeople -= 10;
                        price = (cntPeople * pricePerPerson);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
                else if (day == "Sunday")
                {
                    pricePerPerson = 16;

                    if (cntPeople >= 100)
                    {
                        // price = (cntPeople * pricePerPerson);
                        // price = price - (price * 0.1);
                        // Not 10% !!!

                        cntPeople -= 10;
                        price = (cntPeople * pricePerPerson);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
            }
            else if (typeGroup == "Regular")
            {
                if (day == "Friday")
                {
                    pricePerPerson = 15;

                    if (cntPeople >= 10 && cntPeople <= 20)
                    {
                        price = (cntPeople * pricePerPerson);
                        price = price - (price * 0.05);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
                else if (day == "Saturday")
                {
                    pricePerPerson = 20;
                    if (cntPeople >= 10 && cntPeople <= 20)
                    {
                        price = (cntPeople * pricePerPerson);
                        price = price - (price * 0.05);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
                else if (day == "Sunday")
                {
                    pricePerPerson = 22.50;

                    if (cntPeople >= 10 && cntPeople <= 20)
                    {
                        price = (cntPeople * pricePerPerson);
                        price = price - (price * 0.05);
                        Console.WriteLine($"Total price: {price:f2}");
                    }
                    else
                    {
                        Console.WriteLine($"Total price: {(cntPeople * pricePerPerson):f2}");
                    }
                }
            }
        }
    }
}

Alternative (with decimal instead of double):

using System;

namespace vacation
{
    class Program
    {
        static void Main(string[] args)
        {
            int people = int.Parse(Console.ReadLine());
            string typePeople = Console.ReadLine();
            string day = Console.ReadLine();
            decimal finalPrice = 0.0m;

            switch (day)
            {
                case "Friday":
                    if (typePeople == "Students")
                    {
                        finalPrice += people * 8.45m;

                        if (people >= 30)
                        {
                            finalPrice *= .85m;
                        }
                    }
                    else if (typePeople == "Business")
                    {
                        if (people >= 100)
                        {
                            people -= 10;
                        }

                        finalPrice += people * 10.9m;
                    }
                    else if (typePeople == "Regular")
                    {
                        finalPrice += people * 15.0m;

                        if (people >= 10 && people <= 20)
                        {
                            finalPrice *= .95m;
                        }
                    }
                    break;
                case "Saturday":
                    if (typePeople == "Students")
                    {
                        finalPrice += people * 9.8m;

                        if (people >= 30)
                        {
                            finalPrice *= .85m;
                        }
                    }
                    else if (typePeople == "Business")
                    {
                        if (people >= 100)
                        {
                            people -= 10;
                        }

                        finalPrice += people * 15.6m;
                    }
                    else if (typePeople == "Regular")
                    {
                        finalPrice += people * 20.0m;

                        if (people >= 10 && people <= 20)
                        {
                            finalPrice *= .95m;
                        }
                    }
                    break;
                case "Sunday":
                    if (typePeople == "Students")
                    {
                        finalPrice += people * 10.46m;

                        if (people >= 30)
                        {
                            finalPrice *= .85m;
                        }
                    }
                    else if (typePeople == "Business")
                    {
                        if (people >= 100)
                        {
                            people -= 10;
                        }

                        finalPrice += people * 16.0m;
                    }
                    else if (typePeople == "Regular")
                    {
                        finalPrice += people * 22.5m;

                        if (people >= 10 && people <= 20)
                        {
                            finalPrice *= .95m;
                        }
                    }
                    break;
                default:
                    break;
            }

            Console.WriteLine($"Total price: {finalPrice:F2}");
        }
    }
}

 

0
18/09/2022 16:40:38
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.