daily pastebin goal
68%
SHARE
TWEET

SolarSystem

krasio12356 Apr 16th, 2018 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <cmath>
  4. #include <string>
  5. using namespace std;
  6.                                          // Solar System
  7. struct dat
  8. {
  9.     double distance;
  10.     int days;
  11. };
  12.  
  13. int main()
  14. {
  15.     dat d;
  16.     unordered_map<string, dat> umap;
  17.     d.distance = 0.61;
  18.     d.days = 7;
  19.     umap.emplace("Mercury", d);
  20.     d.distance = 0.28;
  21.     d.days = 14;
  22.     umap.emplace("Venus", d);
  23.     d.distance = 0.52;
  24.     d.days = 20;
  25.     umap.emplace("Mars", d);
  26.     d.distance = 4.2;
  27.     d.days = 5;
  28.     umap.emplace("Jupiter", d);
  29.     d.distance = 8.52;
  30.     d.days = 3;
  31.     umap.emplace("Saturn", d);
  32.     d.distance = 18.21;
  33.     d.days = 3;
  34.     umap.emplace("Uranus", d);
  35.     d.distance = 29.09;
  36.     d.days = 2;
  37.     umap.emplace("Neptune", d);
  38.     string planet;
  39.     getline(cin, planet);
  40.     unordered_map<string, dat>::iterator it = umap.find(planet);
  41.     if (it == umap.end())
  42.     {
  43.         printf("Invalid planet name!\n");
  44.         return 0;
  45.     }
  46.     int days;
  47.     cin >> days;
  48.     if ((days < 1) || (days > umap[planet].days))
  49.     {
  50.         printf("Invalid number of days!\n");
  51.         return 0;
  52.     }
  53.     double totaldays = 226 * 2 * umap[planet].distance + days;
  54.     printf("Distance: %.2f\nTotal number of days: %.2f\n", 2 * umap[planet].distance, totaldays);
  55.     return 0;
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top