Attached is my code for my homework for my C++ class. My problem comes from when I run the program. It returns a value of 1 every single time for the output of the "is it a leap year or not" part of my program. Then, when it outputs the ordinal date of the year the program returns a value like -14300986, when the actual value should be between 1 and 365. I searched all over the net and this site, finding partial help that has allowed me to get this far. The assignment statement can be viewed here: http://www.cs.mtsu.edu/~jsigle/1170/projects/project4.txt :I would ask my teacher for help on this except he has changed the due date to a day that doesn't coincide with my schedule, therefore I can't go to him for help. Any help would be highly appreciated, and if anyone doesn't want to give me the exact answer to my problem, then examples are welcome as well. I want to learn this, I'll take the easy answer. But if someone wants to take the time, I would like to learn what I'm doing wrong. Thank you.
#include <iostream>
using namespace std;
bool isLeapYear (int year)
{
if (year%400 == 0 || year%4 == 0)
{
return true;
cout << "Year is a Leap Year." << endl;
}
else
{
return false;
cout << "Year is not a leap year." << endl;
}
}
int main()
{
int month;
int day;
int year;
int ordinalDay;
// Input date
cout << "Please type in a date in the form MM DD YYYY: ";
cin >> month >> day >> year;
// Calculate Ordinal Day of the Year and display it
if (!isLeapYear)
{
if (month == 1)
{
ordinalDay == day;
}
if (month == 2)
{
ordinalDay == 31 + day;
}
if (month == 3)
{
ordinalDay == 59 + day;
}
if (month == 4)
{
ordinalDay == 90 + day;
}
if (month == 5)
{
ordinalDay == 120 + day;
}
if (month == 6)
{
ordinalDay == 151 + day;
}
if (month == 7)
{
ordinalDay == 181 + day;
}
if (month == 8)
{
ordinalDay == 212 + day;
}
if (month == 9)
{
ordinalDay == 243 + day;
}
if (month == 10)
{
ordinalDay == 273 + day;
}
if (month == 11)
{
ordinalDay == 304 + day;
}
if (month == 12)
{
ordinalDay == 334 + day;
}
}
else if (isLeapYear)
{
if (month == 1)
{
ordinalDay == day;
}
if (month == 2)
{
ordinalDay == 31 + day;
}
if (month == 3)
{
ordinalDay == 60 + day;
}
if (month == 4)
{
ordinalDay == 91 + day;
}
if (month == 5)
{
ordinalDay == 121 + day;
}
if (month == 6)
{
ordinalDay == 152 + day;
}
if (month == 7)
{
ordinalDay == 182 + day;
}
if (month == 8)
{
ordinalDay == 213 + day;
}
if (month == 9)
{
ordinalDay == 244 + day;
}
if (month == 10)
{
ordinalDay == 274 + day;
}
if (month == 11)
{
ordinalDay == 305 + day;
}
if (month == 12)
{
ordinalDay == 335 + day;
}
}
// Display output from leap year function and ordinal day function
cout << isLeapYear << endl;
cout << "Ordinal Day Is: " << ordinalDay << endl;
return 0;
}