#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <stdio.h>
#include <math.h>
using namespace std;
int main ()
{
int y1, y2, m1, m2, d1, d2;
cout << "Please enter the first date" << endl;
do
{
cout << "Enter year ";
cin >> y1;
system("cls");
} while(y1<0);
do
{ cout << "Enter Month ";
cin >> m1;
system("cls");
}
while(m1<0 || m1 >12);
if(m1==2)
{
do
{ cout << "Enter day ";
cin >> d1;
}
while (d1<0 || d1 >28);
system("cls");
} else
{
do
{
cout << "Enter day ";
cin >> d1;
}
while (d1<0 || d1 >31);
system("cls");
}
cout << "Please enter the second date" << endl;
do { cout << "Enter year ";
cin >> y2;
system("cls");
}
while(y2<0);
do
{
cout << "Enter Month ";
cin >> m2;
system("cls");
}
while(m2<0 || m2>12);
if(m2==2)
{
do
{
cout << "Enter day ";
cin >> d2;
}
while (d2<0 || d1 >28);
system("cls");
}
else
{
do
{
cout << "Enter day ";
cin >> d2;
}
while (d2<0 || d1 >31);
system("cls");
}
system("cls");
int y;
int m;
int d;
y = abs(y2-y1);
m = abs(m2-m1);
d = abs(d2-d1);
cout << "The difference between dates is: " << y << " years "<<m<<"
months "<<d<<"days"<<endl;
system("PAUSE");
};
Comments
Leave a comment