88 942
Assignments Done
97.1%
Successfully Done
In July 2020

# Answer to Question #36886 in C++ for Qamar Iqbal

Question #36886
How to Write a program that takes two dates from user in dd/mm/yy and prints difference between given two dates.
1
2017-03-20T11:27:10-0400
#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");           };

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!