Advertisement
TodorovP

Friendly Trip

Jan 24th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Friendly_Trip
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var distance = int.Parse(Console.ReadLine()); //0...10 000km
  14.             var norm = int.Parse(Console.ReadLine()); //0.100 liters/100km
  15.             var priceFuel = double.Parse(Console.ReadLine()); //0...50.0 lv./liter
  16.             var budget = int.Parse(Console.ReadLine()); //0...100 000 разполагаема сума
  17.  
  18.             double sumLitres = distance * norm / 100; //общо гориво
  19.             double sum = sumLitres * priceFuel; //сума за горивото
  20.             double difference = Math.Abs(sum - budget); //разлика
  21.             double forEach = budget / 5.0; //допълнително от всеки
  22.  
  23.             if (sum <= budget)
  24.             {
  25.                 Console.WriteLine($"You can take a trip. {difference:f2} money left.");
  26.             }
  27.             else
  28.             {
  29.                 Console.WriteLine($"Sorry, you cannot take a trip. Each will receive " +
  30.                     $"{forEach:f2} money.");
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement