Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. // Date Diffrence in days //
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.  
  7. long int year_high;
  8. long int year_low;
  9. long int leap_number;
  10. long int days_in_years;
  11. long int month_high;
  12. long int month_low;
  13. int day_low;
  14. int day_high;
  15. long int total_days;
  16. int months[] = {31,59,90,120,151,181,212,243,273,304,334,365}; //month days in array
  17. int main () {
  18.    
  19.     cout << "Please Enter dates in format dd mm yyyy " << "\n";
  20.     cin >> day_high >> month_high >> year_high ;
  21.     cin >>  day_low >> month_low >> year_low;
  22.    
  23.     for (int i = year_low; i < year_high;i++){// for loop will stop when all leap years are worked out
  24.         if(i % 400 ==0 || (i % 100 != 0 && i % 4 == 0)) // year is / by 400, and if it is not / 100 but also / by 4
  25.              leap_number++; }
  26.  
  27.        
  28.     month_high = months[month_high-1]; //calling days from array
  29.     month_low = months[month_low-1 ];
  30.  
  31.     days_in_years = (year_high - year_low) * 365; // working out number of years, then convert to day
  32.     total_days = ((month_high - month_low) + (day_high - day_low)  + days_in_years + leap_number);
  33.  
  34.     cout << "Total Days Diffrence is " << total_days <<"\n";
  35.  
  36. return (0);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement