Професионална програма
Loading...
huki999 avatar huki999 0 Точки

Fund C# Basic and Syntax Exercise 03. Vacation. I have 91% in Judge , pls help !

using System;

namespace Vacation
{
    class Program
    {
        static void Main(string[] args)
        {
            int people = int.Parse(Console.ReadLine());
            string group = Console.ReadLine();
            string weekDay = Console.ReadLine();

            double price = 0;
            double otstupka = 0;

            if (group == "Students")
            {
                if (weekDay == "Friday")
                {
                    price = 8.45;
                }
                else if (weekDay == "Saturday")
                {
                    price = 9.80;
                }
                else if (weekDay == "Sunday")
                {
                    price = 10.46;
                }
                price = price * people;

                if (people < 30)
                {
                    Console.WriteLine($"Total price: {price:F2}");
                }
                if (people >= 30)
                {
                    otstupka = price - price * 15 / 100;
                    Console.WriteLine($"Total price: {otstupka:F2}");
                }
            }

            if (group == "Business")
            {
                if (weekDay == "Friday")
                {
                    price = 10.90;
                }
                else if (weekDay == "Saturday")
                {
                    price = 15.60;
                }
                else if (weekDay == "Sunday")
                {
                    price = 16.0;
                }
                price = price * people;

                if (people < 100)
                {
                    Console.WriteLine($"Total price: {price:F2}");
                }

                if (people >= 100)
                {
                    otstupka = (people - 10) * price;
                    Console.WriteLine($"Total price: {otstupka:F2}");
                }
            }

            if (group == "Regular")
            {
                if (weekDay == "Friday")
                {
                    price = 15.0;
                }
                else if (weekDay == "Saturday")
                {
                    price = 20.0;
                }
                else if (weekDay == "Sunday")
                {
                    price = 22.50;
                }
                price = price * people;

                if (people >= 10 && people<= 20)
                {
                    otstupka = price - price * 5 / 100;
                    Console.WriteLine($"Total price: {otstupka:F2}");
                }
                else
                {
                    Console.WriteLine($"Total price: {price:F2}");
                }
            }
        }
    }
}

 

Тагове:
0
Programming Fundamentals 21/05/2019 22:06:06
JulianJulianov avatar JulianJulianov 4 Точки

Здравей!  Грешката ти е, че първо  си сметнал цената price = price * people;  и после отстъпката  otstupka = (people - 10) * price;. Това важи само за групата Business! И както знаеш кода запаметява винаги последното, в случая price , който като число е например 160 = 16 * 100; и стигайки до реда с остъпката otstupka = (people - 10) * price; се случва това 14400 = (100 - 10) * 160, което е вярно като математически израз, но не и като логически , нали?  Тук price трябва да е само 16, а не десет пъти повече! Размених им местата и ми даде 100/100.

using System;

namespace _04PrintAndSum
{
    class Program
    {
        static void Main(string[] args)
        {
            int people = int.Parse(Console.ReadLine());
            string group = Console.ReadLine();
            string weekDay = Console.ReadLine();

            double price = 0;
            double otstupka = 0;

            if (group == "Students")
            {
                if (weekDay == "Friday")
                {
                    price = 8.45;
                }
                else if (weekDay == "Saturday")
                {
                    price = 9.80;
                }
                else if (weekDay == "Sunday")
                {
                    price = 10.46;
                }
                price = price * people;

                if (people < 30)
                {
                    Console.WriteLine($"Total price: {price:F2}");
                }
                if (people >= 30)
                {
                    otstupka = price - price * 15 / 100;
                    Console.WriteLine($"Total price: {otstupka:F2}");
                }
            }
            if (group == "Business")
            {
                if (weekDay == "Friday")
                {
                    price = 10.90;
                    if (people >= 100)
                    {
                        otstupka = (people - 10) * price;
                        Console.WriteLine($"Total price: {otstupka:F2}");
                    }
                }
                else if (weekDay == "Saturday")
                {
                    price = 15.60;
                    if (people >= 100)
                    {
                        otstupka = (people - 10) * price;
                        Console.WriteLine($"Total price: {otstupka:F2}");
                    }
                }
                else if (weekDay == "Sunday")
                {
                    price = 16.0;
                    if (people >= 100)
                    {
                        otstupka = (people - 10) * price;
                        Console.WriteLine($"Total price: {otstupka:F2}");
                    }
                }
                price = price * people;
                if (people < 100)
                {
                    Console.WriteLine($"Total price: {price:F2}");
                }
            }
            if (group == "Regular")
            {
                if (weekDay == "Friday")
                {
                    price = 15.0;
                }
                else if (weekDay == "Saturday")
                {
                    price = 20.0;
                }
                else if (weekDay == "Sunday")
                {
                    price = 22.50;
                }
                price = price * people;

                if (people >= 10 && people <= 20)
                {
                    otstupka = price - price * 5 / 100;
                    Console.WriteLine($"Total price: {otstupka:F2}");
                }
                else
                {
                    Console.WriteLine($"Total price: {price:F2}");
                }
            }
        }
    }
}
 

0
10/09/2019 21:02:01