1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#include<iostream>
using namespace std;
void isLeapYear (int y);
void daysInMonth (int d, int m, int y);
void numberOfDays (int d, int m, int t1, int t2, int t3);
int main()
{
int days, month, year, tday;
cout<<"Welcome to the Days Calculation"<<endl;
cout<<"We will kindly calculate the number of the days based on your input (dates)"<<endl<<endl;
do
{
cout<<"Please input the dates (Day Month Year):"<<endl;
cin>>days>>month>>year;
isLeapYear (year);
daysInMonth (days, month, year);
if ( month < 1 || month > 12 )
{
cout << "INVALID: Please input month between 1-12 (Enter the dates again):"<<endl;
}
if ( days < 1 || days > 31 )
{
cout << "INVALID: Please input day between 1-31 (Enter the dates again):" << endl;
}
}
while (month < 1 || month > 12 || days < 1 || days > 31 );
return 0;
}
void isLeapYear (int y)
{
if (y%4==0 && y%100!=0)
{
cout<<y<<" is a leap year"<<endl;
}
else if (y%100==0 && y%400==0)
{
cout<<y<<" is a leap year"<<endl;
}
else
cout<<y<<" is not a leap year"<<endl;
}
void daysInMonth (int d, int m, int y)
{
int tday1, tday2, tday3, tday4;
if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10)
tday1 =31;
if (m==2)
tday2 =28;
if (m==4 || m==6 || m==9 || m==11)
tday3 =30;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
{
if (m==2)
tday2 =29;
}
numberOfDays (d, m, tday1, tday2, tday3);
}
void numberOfDays (int d, int m, int t1, int t2, int t3)
{
int total=0;
if (m==1)
total = d;
if (m==2)
total = d + t1;
if(m==3)
total = d + t1 +t2;
if (m==4)
total = d + t1 + t1 + t2;
if (m==5)
total = d + t1 + t1 + t2 + t3;
if (m==6)
total = d + t1 + t1 + t2 + t3 + t1;
if (m==7)
total = d + t1 + t1 + t2 + t3 + t1 + t3;
if (m==8)
total = d + t1 + t1 + t2 + t3 + t1 + t3 + t1;
if (m==9)
total = d + t1 + t1 + t2 + t3 + t1 + t3 + t1 + t1;
if (m==10)
total = d + t1 + t1 + t2 + t3 + t1 + t3 + t1 + t1 + t3;
if (m==11)
total = d + t1 + t1 + t2 + t3 + t1 + t3 + t1 + t1 + t3 + t1;
if (m==12)
total = d + t1 + t1 + t2 + t3 + t1 + t3 + t1 + t1 + t3 + t1 + t3;
cout<<"the total days "<<total<<endl;
}
|