Skip to content

Commit 4eb83a0

Browse files
committed
script added
1 parent 9698231 commit 4eb83a0

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

C++/counting-days/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Counting days left to birthday
2+
- - - - - -
3+
## Aim
4+
Aim of the script is to count the number of days left to your birthday
5+
6+
## To use
7+
Run ```count.cpp```</br>
8+
Enter the day,month and year of upcoming birthday

C++/counting-days/count.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <iostream>
2+
#include <ctime>
3+
using namespace std;
4+
int main()
5+
{
6+
// asking user input for next birthday
7+
time_t now = time(0);
8+
tm *ltm = localtime(&now);
9+
int m,d,y;
10+
cout<<"Enter month of birthday ";
11+
cin>>m;
12+
cout<<"Enter day of birthday ";
13+
cin>>d;
14+
cout<<"Enter the year of your next birthday";
15+
cin>>y;
16+
17+
//current day and date
18+
19+
int current_day = ltm->tm_mday;
20+
int current_month = 1+(ltm->tm_mon);
21+
int current_year = 1900 +(ltm->tm_year);
22+
int monthDays[12]= { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
23+
int middle_days;
24+
middle_days= 0;
25+
26+
27+
//if birthday falls the same year
28+
if(current_year == y)
29+
30+
{
31+
//fallling same month
32+
if(current_month==m)
33+
{
34+
cout<<d-current_day;
35+
}
36+
else
37+
//different month
38+
{
39+
for(int i = current_month; i<m-1;i++)
40+
middle_days+=monthDays[i];
41+
cout<<d+(monthDays[current_month-1]-current_day)+middle_days;
42+
}
43+
44+
cout<<" days are left for your birthday";
45+
}
46+
47+
middle_days = 0;
48+
//if birthday falls the next year
49+
if(current_year != y)
50+
{
51+
for(int i = current_month;i<12;i++)
52+
{
53+
middle_days+=monthDays[i];
54+
}
55+
for(int i = 0;i<m-1;i++)
56+
{
57+
middle_days+=monthDays[i];
58+
}
59+
cout<<d+(monthDays[current_month-1]-current_day)+middle_days;
60+
cout<<" days are left for your birthday"<<endl;
61+
}
62+
63+
}

0 commit comments

Comments
 (0)