Advertisement
notjacob

C++ time until Christmas in progress

Dec 1st, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.    
  7. clock_t start = clock();
  8. tm* my_time;
  9. time_t t = time(NULL);
  10.    
  11.    
  12. char* charTime = ctime(&t);
  13. cout << charTime;
  14. my_time = localtime(&t);
  15. int day = my_time->tm_mday;
  16. int month = my_time->tm_mon + 1;
  17. int year = my_time->tm_year + 1900;
  18.  
  19. int chm = 12;
  20. int chd = 25;
  21.  
  22. int tmtd = 0;
  23. int tmtm = 0;
  24.  
  25. int jan = 31;
  26. int feb = 28;
  27. int mar = 31;
  28. int apr = 30;
  29. int may = 31;
  30. int jun = 30;
  31. int jul = 31;
  32. int aug = 31;
  33. int sep = 30;
  34. int oct = 31;
  35. int nov = 30;
  36. int dec = 31;
  37.  
  38. int mdays = 0;
  39. if (month == chm) {
  40.     if (day == chd) {
  41.         cout << "It is christmas!";
  42.     }
  43.     else if (day != chd && day < 25) {
  44.         tmtd = chd - day;
  45.         cout << "There are " << tmtd << " days until Christmas";
  46.     }
  47.     else if (day != chd && day > 25) {
  48.         tmtd = 365 - (30 - day);
  49.         cout << "There are " << tmtd << " days until Christmas";
  50.     }
  51.     else {
  52.         cout << "Error";
  53.     }
  54. }
  55.  
  56. else if (month != chm) {
  57.     tmtm = chm - month;
  58.    
  59.     if (month == 1) {
  60.         mdays = jan;
  61.         tmtd = mdays - 5;
  62.         cout << "There are 11 months and " << mdays << " days until Christmas";
  63.     }
  64. }
  65.  
  66.    
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement