SHARE
TWEET

Untitled

a guest Nov 19th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. string findMonth(int x) {
  6.    if (x >= 1 && x <= 31)
  7.       return "jan";
  8.    else if (x >= 32 && x <= 59)
  9.       return "feb";
  10.    else if (x >= 60 && x <= 90)
  11.       return "mar";
  12.    else if (x >= 91 && x <= 120)
  13.       return "apr";
  14.    else if (x >= 121 && x <= 151)
  15.       return "may";
  16.    else if (x >= 152 && x <= 181)
  17.       return "jun";
  18.    else if (x >= 182 && x <= 212)
  19.       return "jul";
  20.    else if (x >= 213 && x <= 243)
  21.       return "aug";
  22.    else if (x >= 244 && x <= 273)
  23.       return "sep";
  24.    else if (x >= 274 && x <= 304)
  25.       return "oct";
  26.    else if (x >= 305 && x <= 334)
  27.       return "nov";
  28.    else if (x >= 335 && x <= 365)
  29.       return "dec";
  30.    else if (x > 365 || x < 1)
  31.       return "inv";
  32. }
  33.  
  34. int findDay(int x) {
  35.    int y = 0;
  36.    if (x > 365)
  37.       x = x - 365;
  38.    if (x > 0 && x < 32)
  39.       return x;
  40.    else if (x >= 32 && x <= 59) {
  41.       y = x - 31;
  42.       return y;
  43.    }
  44.    else if (x >= 60 && x <= 90) {
  45.       y = x - 59;
  46.       return y;
  47.    }
  48.    else if (x >= 91 && x <= 120) {
  49.       y = x - 90;
  50.       return y;
  51.    }
  52.    else if (x >= 121 && x <= 151) {
  53.       y = x - 120;
  54.       return y;
  55.    }
  56.    else if (x >= 152 && x <= 181) {
  57.       y = x - 151;
  58.       return y;
  59.    }
  60.    else if (x >= 182 && x <= 212) {
  61.       y = x - 181;
  62.       return y;
  63.    }
  64.    else if (x >= 213 && x <= 243) {
  65.       y = x - 212;
  66.       return y;
  67.    }
  68.    else if (x >= 244 && x <= 273) {
  69.       y = x - 243;
  70.       return y;
  71.    }
  72.    else if (x >= 274 && x <= 304) {
  73.       y = x - 273;
  74.       return y;
  75.    }
  76.    else if (x >= 305 && x <= 334) {
  77.       y = x - 304;
  78.       return y;
  79.    }
  80.    else if (x >= 335 && x <= 365) {
  81.       y = x - 334;
  82.       return y;
  83.    }
  84.    else if (x < 1 || x > 365)
  85.       return 0;
  86. }
  87.  
  88. int main() {
  89.    
  90.    int input = 1, day = 0, ya = 0;
  91.    string mo;
  92.    
  93.    cout << "Please enter a day of the year (0 to exit): ";
  94.    cin >> input;
  95.    cout << input << endl;
  96.    
  97.    while (input != 0) {
  98.       if (input > 365) {
  99.          ya = (double)input / 365;
  100.          cout << ya << " year" << endl;
  101.          //mo = findMonth (input - (365*ya));
  102.          //day = findDay (input - (365*ya));
  103.          //cout << mo << " " << day << endl;
  104.       }
  105.       else {
  106.          mo = findMonth(input);
  107.          day = findDay(input);
  108.          cout << mo << " " << day << endl;
  109.       }
  110.      
  111.       cout << "Please enter a day of the year (0 to exit): ";
  112.       cin >> input;
  113.       cout << input << endl;
  114.    }
  115.    
  116.    cout << "Thanks for playing!" << endl;
  117.    
  118.    return 0;
  119. }
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