Loading...
CryptoPimp avatar CryptoPimp 0 Точки

Квартално магазинче C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace daSiEbe
{
    class Program
    {
        static void Main(string[] args)
        {
            string town = Console.ReadLine();
            string product = Console.ReadLine();

            
            double quantity = double.Parse(Console.ReadLine());

            double result = 0;



            if (town == "Sofia")
            {
                if (product == "coffee")
                {
                    result = quantity * 0.50;
                }
                else if (product == "beer")
                {
                    result = quantity * 0.80;
                }
                else if (product == "beer")
                {
                    result = quantity * 1.20;
                }
                else if (product == "sweets")
                {
                    result = quantity * 1.45;
                }
                else
                {
                    result = quantity * 1.60;
                }
            }
            else if (town == "Plovdiv")
            {
                if (product == "coffee")
                {
                    result = quantity * 0.40;
                }
                else if (product == "beer")
                {
                    result = quantity * 0.70;
                }
                else if (product == "beer")
                {
                    result = quantity * 1.15;
                }
                else if (product == "sweets")
                {
                    result = quantity * 1.30;
                }
                else
                {
                    result = quantity * 1.50;
                }

            }
            else
            {
                if (product == "coffee")
                {
                    result = quantity * 0.45;
                }
                else if (product == "beer")
                {
                    result = quantity * 0.70;
                }
                else if (product == "beer")
                {
                    result = quantity * 1.10;
                }
                else if (product == "sweets")
                {
                    result = quantity * 1.35;
                }
                else
                {
                    result = quantity * 1.55;
                }

                Console.WriteLine(result);

            }
        }

    }
}

Здравейте колеги това е кода ми може ли някой да ми помогне judge ми дава само 6 точки, не мисля че е чак толкова зле, немога да разбера къде съм объркал, моля помогнете

0
Programming Basics
avasilev1 avatar avasilev1 19 Точки
Best Answer

 

1. Размени местата на променливите. Писал си: string town = Console.ReadLine();  string product = Console.ReadLine(); а judge подава първо продукта и после града. => трябва да стане:

string product= Console.ReadLine();

string town= Console.ReadLine();

2. В if-овете си сложил по два пъти beer, а трябва да има и water.

3. Console.WriteLine(results) трябва да е извън последния if.

 

Eто поправения код: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace daSiEbe
{
    class Program
    {
        static void Main(string[] args)
        {
            string product = Console.ReadLine();
			string town = Console.ReadLine();

            
            double quantity = double.Parse(Console.ReadLine());

            double result = 0;



            if (town == "Sofia")
            {
                if (product == "coffee")
                {
                    result = quantity * 0.50;
                }
                else if (product == "water")
                {
                    result = quantity * 0.80;
                }
                else if (product == "beer")
                {
                    result = quantity * 1.20;
                }
                else if (product == "sweets")
                {
                    result = quantity * 1.45;
                }
                else
                {
                    result = quantity * 1.60;
                }
            }
            else if (town == "Plovdiv")
            {
                if (product == "coffee")
                {
                    result = quantity * 0.40;
                }
                else if (product == "water")
                {
                    result = quantity * 0.70;
                }
                else if (product == "beer")
                {
                    result = quantity * 1.15;
                }
                else if (product == "sweets")
                {
                    result = quantity * 1.30;
                }
                else
                {
                    result = quantity * 1.50;
                }

            }
            else
            {
                if (product == "coffee")
                {
                    result = quantity * 0.45;
                }
                else if (product == "water")
                {
                    result = quantity * 0.70;
                }
                else if (product == "beer")
                {
                    result = quantity * 1.10;
                }
                else if (product == "sweets")
                {
                    result = quantity * 1.35;
                }
                else
                {
                    result = quantity * 1.55;
                }


            }
          Console.WriteLine(result);
        }

    }
}

 

0
05/06/2018 20:58:46
CryptoPimp avatar CryptoPimp 0 Точки

Много ти Благодаря !!! Бях започнал да се отчайвам  yes yes yes yes yes yes yes yes yes

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