Printing the date from starting date to ending date

This is an article on Printing the date from starting date to ending date in C++.

Rated 4.50 By 2 users

Printing the date from starting date to ending date

The program takes the starting date and ending date as inputs and prints the dates in between them.This program is useful if u r dealing with dates.

The code

I have used four date functions i.e date1() , date2() , date3() , date4(). When the starting year and ending year is same it performs date1() function.If the month is equal to starting month then it performs date2() function.If the month is equal to ending month it performs date3() function.If the year is in between starting and ending year then it performs date4() function.

Code: Cpp

#include<iostream>usingnamespace std;

int date1(int , int , int , int , int , int);

int date2(int , int , int , int);

int date3(int , int , int , int);

int date4(int , int);

main(){

cout<<"Enter the starting date, month and year"<<endl;

int sd,sm,sy,ed,em,ey;

cin>>sd>>sm>>sy;

cout<<"Enter the ending date, month and year"<<endl;

cin>>ed>>em>>ey;

int i,j,k=0,n,m;

n = ey - sy;

m=sm-em;

if(sy>ey){ cout<<"Starting year cannot be greater than ending year"<<endl;exit(1);}if(n==0&&sm>em){ cout<<"Date entered is wrong"<<endl;exit(1);}