(C++)I need to create a program that would input year and month in number. Display the year and the number of days in that month. The hard part is I need to include the leap year e.g. if the input year is 2000 and the input month is 2 (which is February) the output no. of days must be "29 Days".

I wish you can help. Anyways, thanks in advance.

#include <iostream>
using namespace std;
void main()
{
	int month, year;
	int monthA[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	cout<<"Input Month and Year ==> "<<endl;
	cin>>month>>year;

	if ((year%4==0||year%400==0)&&month==2)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[1]+1<<" days"<<endl;
	else if((year%4!=0||year%400!=0)&&month==2)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[1]<<" days"<<endl;
	else if (month==1)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==3)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==4)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==5)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==6)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==7)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==8)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==9)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==10)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==11)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if (month==12)
		cout<<"Year: "<<year<<" "<<"Month"<<month<<"=>"<<monthA[month-1]<<" days"<<endl;
	else if((month>=13||month<=0)||(year<=0))
		cout<<"Invalid Input!"<<endl;
}

This is my code...I need to use pointers but I dunno how to use it so i ended up doing this barbaric code ;< Thanks.

Edited 5 Years Ago by Narue: Added code tags

This article has been dead for over six months. Start a new discussion instead.