Advertisement
Guest User

Untitled

a guest
Jun 14th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         string nameOfPlanet = Console.ReadLine();
  9.         int daysOfStaying = int.Parse(Console.ReadLine());
  10.  
  11.         double distance = 0;
  12.         double calculate = 0;
  13.         bool validPlanet = true;
  14.         bool validNumberOfDays = true;
  15.  
  16.         if (nameOfPlanet == "Mercury")
  17.         {
  18.             if (daysOfStaying <= 7)
  19.             {
  20.                 distance = 0.61 * 2;
  21.                 calculate = 2 * (226 * 0.61) + daysOfStaying;
  22.             }
  23.             else
  24.             {
  25.                 validNumberOfDays = false;
  26.             }
  27.         }
  28.         else if (nameOfPlanet == "Venus")
  29.         {
  30.             if (daysOfStaying <= 14)
  31.             {
  32.                 distance = 0.28 * 2;
  33.                 calculate = 2 * (226 * 0.28) + daysOfStaying;
  34.             }
  35.             else
  36.             {
  37.                 validNumberOfDays = false;
  38.             }
  39.  
  40.         }
  41.         else if (nameOfPlanet == "Mars")
  42.         {
  43.             if (daysOfStaying <= 20)
  44.             {
  45.                 distance = 0.52 * 2;
  46.                 calculate = 2 * (226 * 0.52) + daysOfStaying;
  47.             }
  48.             else
  49.             {
  50.                 validNumberOfDays = false;
  51.             }
  52.         }
  53.         else if (nameOfPlanet == "Jupiter")
  54.         {
  55.             if (daysOfStaying <= 5)
  56.             {
  57.                 distance = 4.2 * 2;
  58.                 calculate = 2 * (226 * 4.2) + daysOfStaying;
  59.             }
  60.             else
  61.             {
  62.                 validNumberOfDays = false;
  63.             }
  64.         }
  65.         else if (nameOfPlanet == "Saturn")
  66.         {
  67.             if (daysOfStaying <= 3)
  68.             {
  69.                 distance = 8.52 * 2;
  70.                 calculate = 2 * (226 * 8.52) + daysOfStaying;
  71.             }
  72.             else
  73.             {
  74.                 validNumberOfDays = false;
  75.             }
  76.         }
  77.         else if (nameOfPlanet == "Uranus")
  78.         {
  79.             if (daysOfStaying <= 3)
  80.             {
  81.                 distance = 2 * 18.21;
  82.                 calculate = 2 * (226 * 18.21) + daysOfStaying;
  83.             }
  84.             else
  85.             {
  86.                 validNumberOfDays = false;
  87.             }
  88.         }
  89.         else if (nameOfPlanet == "Neptune")
  90.         {
  91.             if (daysOfStaying <= 2)
  92.             {
  93.                 distance = 29.09 * 2;
  94.                 calculate = 2 * (226 * 29.09) + daysOfStaying;
  95.             }
  96.             else
  97.             {
  98.                 validNumberOfDays = false;
  99.             }
  100.         }
  101.         else
  102.         {
  103.             validPlanet = false;
  104.         }
  105.  
  106.         if (!validPlanet)
  107.         {
  108.             Console.WriteLine("Invalid planet name!");
  109.         }
  110.         else if (!validNumberOfDays)
  111.         {
  112.             Console.WriteLine("Invalid number of days!");
  113.         }
  114.         else
  115.         {
  116.             Console.WriteLine("Distance: {0}", $"{distance:F2}");
  117.             Console.WriteLine("Total number of days: {0}", $"{calculate:F2}");
  118.         }
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement