Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. Converter
  2. You want to buy this really cool car from the UK, but you are worried about the fuel consumption. The values you see are MPG (miles per gallon). You have no idea what 20 MPG means so, being a programmer, decide to write a converter that helps you calculate the consumption.
  3.  
  4. Doing some research, you learn that 1 gallon = 4.54 litres and 1 mile = 1.6 km.
  5.  
  6. After the calculation, round the result down to the neareast whole number.
  7.  
  8. Input
  9. On the first line you will receive a number m - miles per galon
  10. Output
  11. On the only line of output, print {result} litres per 100 km
  12. Constraints
  13. 1 <= m <= 100
  14. Input
  15. 20
  16. Output
  17. 14 litres per 100 km
  18. Input
  19. 44
  20. Output
  21. 6 litres per 100 km
  22. C#
  23. using System;
  24.  
  25. namespace _09_Converter
  26. {
  27.     class Program
  28.     {
  29.         static void Main(string[] args)
  30.         {
  31.             int milesPerGalon = int.Parse(Console.ReadLine());
  32.  
  33.  
  34.             if (1 < milesPerGalon || milesPerGalon < 100)
  35.             {
  36.  
  37.                 double km = (milesPerGalon * 1.0);
  38.                 double perHundred = Math.Floor(282.48 / km);
  39.                 Console.WriteLine($"{perHundred} litres per 100 km");
  40.             }
  41.  
  42.         }
  43.     }
  44. }
  45. Test case #4: Wrong Answer [0.03 s, 14.0 MB]
  46. Your output (clipped)
  47. 282 litres per 100 km
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement