I tried making a program for calculating the difference between two dates on CPP, it does work, but it is not completely accurate.
The program calculates the number of months and multiplies it by 30. The problem here is that all months don't have 30 days. A few has 31 and one has 28/29. My program is below. Can anyone suggest me any changes to get rid of this problem.
The program calculates the number of months and multiplies it by 30. The problem here is that all months don't have 30 days. A few has 31 and one has 28/29. My program is below. Can anyone suggest me any changes to get rid of this problem.
Code:
#include<iostream.h> #include<conio.h> #include<time.h> #include<string.h> void main() { char a[20]; char b[20]; int t,q,m,c,d,e,h,i,k,r,s,u,aa,bb,cc,dd,ee,ff; float aaa=0,bbb,ccc,ddd,eee,fff,ll; clrscr(); cout<<"\nEnter The first date\n"; cin>>b; t=b[3]; q=b[4]; m=((t-48)*10)+(q-48); h=b[0]; i=b[1]; k=((h-48)*10)+(i-48); aa=b[6]; bb=b[7]; cc=((aa-48)*10)+(bb-48); cout<<"\nEnter The second date\n"; cin>>a; c=a[3]; d=a[4]; e=((c-48)*10)+(d-48); r=a[0]; s=a[1]; u=((r-48)*10)+(s-48); dd=a[6]; ee=a[7]; ff=((dd-48)*10)+(ee-48); cout<<"The first date is "<<m<<" And the month is "<<k<<" and the year is "<<cc; cout<<"\nThe second date is "<<e<<" and the month is "<<u<<" and the year is "<<ff; aaa=(u-k)*30; bbb=e-m; ccc=(ff-cc)*365; cout<<"\nThe diff is"<<aaa+bbb+ccc; getch(); }
Comment