Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date Diffrence in days //
- #include <iostream>
- using namespace std;
- long int year_high;
- long int year_low;
- long int leap_number;
- long int days_in_years;
- long int month_high;
- long int month_low;
- int day_low;
- int day_high;
- long int total_days;
- int months[] = {31,59,90,120,151,181,212,243,273,304,334,365}; //month days in array
- int main () {
- cout << "Please Enter dates in format dd mm yyyy " << "\n";
- cin >> day_high >> month_high >> year_high ;
- cin >> day_low >> month_low >> year_low;
- for (int i = year_low; i < year_high;i++){// for loop will stop when all leap years are worked out
- if(i % 400 ==0 || (i % 100 != 0 && i % 4 == 0)) // year is / by 400, and if it is not / 100 but also / by 4
- leap_number++; }
- month_high = months[month_high-1]; //calling days from array
- month_low = months[month_low-1 ];
- days_in_years = (year_high - year_low) * 365; // working out number of years, then convert to day
- total_days = ((month_high - month_low) + (day_high - day_low) + days_in_years + leap_number);
- cout << "Total Days Diffrence is " << total_days <<"\n";
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement