Advertisement
Guest User

BeersForTrip

a guest
May 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5.  
  6. namespace RegexEx
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.            
  13.             int tripInMiles = int.Parse(Console.ReadLine());
  14.             double tripInKms = tripInMiles * 1.609344;
  15.             double totalQuantityOfBeers = 0;
  16.             string input = "";
  17.  
  18.  
  19.             while ((input = Console.ReadLine())!= "trip ended")
  20.             {
  21.                 //string[] info =  input.Split(", ");
  22.                 // string name = info[0];
  23.                 // double km = double.Parse(info[1]);
  24.                 // double beers = double.Parse(info[2]);
  25.                 string name = input;
  26.                 double km = double.Parse(Console.ReadLine());
  27.                 double beers = double.Parse(Console.ReadLine());
  28.                 double beersPerKm = beers / km;
  29.                 totalQuantityOfBeers += beersPerKm * tripInKms;
  30.  
  31.                
  32.  
  33.             }
  34.            
  35.             Console.WriteLine($"Beers needed for the trip: {Math.Ceiling(totalQuantityOfBeers)}");
  36.  
  37.         }
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement