settingsAccountsettings
Menusettings

Q: Bai Ivan Adventures (C# Task)

+5 votes

Bai Ivan wants to drink himself to death. However, he doesn’t always have enough money and the alcohol costs a different amount of money depending on the day of the week. Also, for every day he has decided that he needs to drink a different amount of alcohol.

You will receive several numbers as input from the console. You will receive an integer that represents the day of the week. 0 means Monday and 6 means Sunday. Then you will receive a floating-point number that shows the amount of money that Bai Ivan has. On the last line you will receive the amount of alcohol that Bai Ivan wants to drink – also a floating-point number.

Alcohol costs per liter on different days:

  • Monday – 25.0 leva;
  • Tuesday – 21.0 leva;
  • Wednesday – 14.0 leva;
  • Thursday – 17.0 leva;
  • Friday – 45.0 leva;
  • Saturday – 59.0 leva;
  • Sunday – 42.0 leva;

You also need to calculate Bai Ivan’s condition after drinking. If he has drunk more than 1.5l he is “very drunk”. If he has drunk between 1.5l and 1.0l (inclusive) he is “drunk”. Anything less than 1.0 means he is “sober”.

After that, check if Bai Ivan has bought as much alcohol as he wanted. If the bought amount is more than the desired amount, Bai Ivan is very happy and shares the remaining alcohol with his friends. If the bought amount equals the desired amount, Bai Ivan is also happy, but he has nothing to share. Else he is quite sad, and needs some more alcohol to be happy.

Input

  • Input data is read from the console.
  • The integer N is at the first line – the current day of the week, starting from zero.
  • On the second line – a floating-point number that shows how much money Bai Ivan has.
  • On the third line – a floating-point number that shows how much liters of alcohol Bai Ivan wants to drink

The input data will always be valid and in the format described. There is no need to check it explicitly.

Output

  • The output data must be printed on the console.
  • On the only line of input print the following message:
  • If Bai Ivan has drunk more alcohol than he wanted  - “Bai Ivan is {Bai Ivan’s condition} and very happy and he shared {remaining amount of alcohol} l. of alcohol with his friends
  • If Bai Ivan has drunk exactly as much as he wanted – “Bai Ivan is {Bai Ivan’s condition} and happy. He is as drunk as he wanted
  • Else print – “Bai Ivan is {Bai Ivan’s condition} and quite sad. He wanted to drink another {difference between bought and desired alcohol} l. of alcohol”
  • The difference desired – bought alcohol should be formatted to two numbers after the decimal separator

Constraints

  • N will be an integer between 0 and 6, inclusive.
  • Time limit: 0.25 seconds.
  • Allowed memory: 16 MB.

Examples

c sharp task output bai Ivan

C# task useful comments bai Ivan adventures

asked in C# category by user andrew
edited by user golearnweb

1 Answer

+2 votes
 
Best answer

Here is my solution - the comments are very useful!

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


class Task1
{
    static void Main()
    {
        int day = int.Parse(Console.ReadLine());
        decimal moneyHas = decimal.Parse(Console.ReadLine());
        decimal litresWants = decimal.Parse(Console.ReadLine());
        decimal litresHas = 0;

        switch (day)
        {
            case 0: litresHas = (moneyHas / 25.0m);
                break;//Monday – 25.0 leva;
            case 1: litresHas = (moneyHas / 21.0m);
                break;//Tuesday – 21.0 leva;
            case 2: litresHas = (moneyHas / 14.0m);
                break;//Wednesday – 14.0 leva;     
            case 3: litresHas = (moneyHas / 17.0m);
                break;//Thursday – 17.0 leva;
            case 4: litresHas = (moneyHas / 45.0m);
                break;//Friday – 45.0 leva;
            case 5: litresHas = (moneyHas / 59.0m);
                break;//Saturday – 59.0 leva;
            case 6: litresHas = (moneyHas / 42.0m);
                break;//Sunday – 42.0 leva;
            default: Console.WriteLine("Write a number between 0 and 6!");
                break;
        }

        
        string condition = "0";
        if (litresHas > 1.5m)
        {
            condition = "very drunk";
        }

        else if (litresHas >= 1.0m && litresHas < 1.5m)
        {
            condition = "drunk";
        }

        else if (litresHas < 1.0m)
        {
            condition = "sober";
        }

        if (litresHas > litresWants)
        {
            Console.WriteLine("Bai Ivan is {0} and very happy and he shared {1:F2} l. of alcohol with his friends", condition, (litresHas - litresWants));
        }

        else if (litresHas == litresWants)
        {
            Console.WriteLine("Bai Ivan is {0} and happy. He is as drunk as he wanted", condition);
        }

        else if (litresHas < litresWants)
        {
            Console.WriteLine("Bai Ivan is {0} and quite sad. He wanted to drink another {1:F2} l. of alcohol", condition, (litresWants - litresHas));
        }
    }
}
answered by user eiorgert
selected by user andrew
...