Hello all,
I am working with a program to calculate the days in a given month. We are to use functions and bool. I have the below code, which worked until I tried to create the function. I continue to get an error about "numberOfDays" not being initialized however if I state that numberOfDays = 0, that is all i get in return, 0....any suggestions?
//C++ program to determin the number of days in a given month
//of a given year.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int calcDays (int);
int main ()
{
int month, year;
int numberOfDays;
cout <<"Month and year, and I will calculate the number of days in that month. ";
cout <<endl;
cout <<"Enter the month (eg. 02 for February): ";
cin >> month;
cout <<"Enter the year (eg. 2010): ";
cin >>year;
calcDays (numberOfDays);
cout <<"Month "<<"Year "<<"# of Days";
cout <<endl;
cout << setfill('0') << setw(2)<<month<<" "<<year<<" "<<numberOfDays;
cout <<endl;
system ("pause");
return 0;
}
int calcDays (int)
{
int month = 0;
int Days;
int year = 0;
if (month == 4 || month == 6 || month == 9 || month == 11)
Days = 30;
else if (month == 02)
{
bool isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
if (isLeapYear == 0)
Days = 29;
else
Days = 28;
}
else
Days = 31;
return Days;
}