i have to write a function (dayNumber) that returns the day number in a year for a date that is provided as input data. i cant use const, struct, or loops, it has to be very basic stuff. i have something written but i can figure out how to get it to run or what im missing, any clues will help, thanks!!
#include <iostream>
using namespace std;
bool leapYear(int);
int dayNumber(int, int, int);
int monthtable;
int monthtable d[12] =
{
{ 0 }, { 31 }, { 59 }, { 90 }, { 120 },
{ 151 }, { 181 }, { 212 }, { 243 }, { 273 },
{ 304 }, { 334 }
};
int getDayNumber(int month)
{
return d[month - 1].monthtable;
}
int main () //begin main
{
int month;
int day;
int year;
int leap;
int number;
//input
cout << "What month? \n";
cin >> month;
cout << "What day? \n";
cin >> day;
cout << "What four digit year? \n";
cin >> year;
//calculate
leap = leapYear(year);
number = dayNumber(month, day, leap);
//output
cout << "The day number for the date you entered: " << month
<< "/" << day << "/" << year << " is: " << number << endl;
//display true or false
if (leap)
cout << "Year entered is a leap year: true" << endl;
else
cout << "Year entered is a leap year: false" << endl;
system ("pause");
return 0;
}
//bool leapYear begin
bool leapYear(int year)
{
return (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0));
} //end bool
//calculate dayNumber
int dayNumber(int month, int day, int leap)
{
return day + getDayNumber(month) + (month > 2 ? leap : 0);
}