Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Cvetelinpenev avatar Cvetelinpenev 1 Точки

Помощ за задачи от Conditional Statements - More Exercises - C#

Здравейте,

Може ли малко помощ за две задачки?

На задачата Harvest ми изкарва 90/100, не мога да си открия грешките -

https://pastebin.com/7FuP4Piw

Test #10 (Incorrect answer) - това означава ли, че е в края на задачата

 

Също задача Pipes In Pool. Срещнах проблеми с превръщането на цели числа в проценти -

https://pastebin.com/xQBC5932

Тагове:
0
Programming Basics
Axiomatik avatar Axiomatik 2422 Точки
Best Answer

Harvest, 2 problems.

At line 27 string interpolation was not correct :

$"Good harvest this year! Total wine: {Math.Floor(wine)} liters."

should have been used instead of

$"Good harvest this year! Total wine: {wine} liters.", Math.Floor(wine)

=> Math.Floor(wine) will not applied on wine

Line 30, validation with if(neededLitersWine > wine), instead of if(neededLitersWine >= wine)

 

PipesInPool, 2 problems.

Set all the input values to double and don't cast the calculations (int). That way you won't receive percentage numbers. Also, it's easier to use $”” String interpolation for the output text.

 

Code:

using System;

namespace Harvest
{
    class Program
    {
        static void Main()
        {
            //Input
            double vineyard = double.Parse(Console.ReadLine());
            double grape = double.Parse(Console.ReadLine());
            double neededLitersWine = double.Parse(Console.ReadLine());
            int numberOfWorkers = int.Parse(Console.ReadLine());
            double oneLiter = 2.5;

            //Calculation
            var totalGrape = vineyard * grape;

            var wine = 0.40 * totalGrape / oneLiter;

            if (wine >= neededLitersWine)
            {
                double total = Math.Ceiling(wine - neededLitersWine);
                double left = Math.Ceiling(total / numberOfWorkers);
                Console.WriteLine($"Good harvest this year! Total wine: {Math.Floor(wine)} liters.");
                Console.WriteLine("{0} liters left -> {1} liters per person.", total, left);
            }
            else if (neededLitersWine > wine)
            {
                double moreVine = Math.Floor(neededLitersWine - wine);
                Console.WriteLine($"It will be a tough winter! More {moreVine} liters wine needed.");
            }
        }
    }
}

Code:

using System;

namespace TestConditionalStatements
{
    class Program
    {
        static void Main()
        {
            double volumeOfPool = double.Parse(Console.ReadLine());
            double firstPipe = double.Parse(Console.ReadLine());
            double secondPipe = double.Parse(Console.ReadLine());
            double hour = double.Parse(Console.ReadLine());

            var volumeOfFirstPipe = firstPipe * hour;
            var volumeOfSecondPipe = secondPipe * hour;
            var total = volumeOfFirstPipe + volumeOfSecondPipe;

            if (total <= volumeOfPool)
            {
                var full = (total / volumeOfPool) * 100;
                var firstPipeContribution = (volumeOfFirstPipe / total) * 100;
                var secondPipeContribution = (volumeOfSecondPipe / total) * 100;

                //Console.WriteLine($"The pool is {0:f2} % full.Pipe 1: {1:f2}%).Pipe 2: {2:f2}%.", full, firstPipeContribution, secondPipeContribution);
                Console.WriteLine($"The pool is {full:f2} % full. Pipe 1: {firstPipeContribution:f2}%. Pipe 2: {secondPipeContribution:f2}%.");
            }
            else
            {
                var pfull = total - volumeOfPool;
                //Console.WriteLine($"For {0} hours the pool overflows with {1:f2} liters.", hour, pfull);
                Console.WriteLine($"For {hour} hours the pool overflows with {pfull:f2} liters.");
            }
        }
    }
}

 

 

0
Cvetelinpenev avatar Cvetelinpenev 1 Точки

Thank you :) I really appreciate your help. Thank you so much for your detailed explanation :)

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