Requirements
Write the following function:
void splitDate(int dayOfYear, int year, int *month, int *day);
dayOfYear is an integer between 1 and 366, specifying a particular day within the year designated by year. month and day point to variables in which the function will store the equivalent month (1-12) and day within the month(1-31).
Write a main function to test the correctness of your function.
Note: Do consider that February has 29 days for leap years.
Based on my code, is this the right way to go about it or is there a simpler way to do this?
#include <iostream>
#include <stdio.h>
using namespace std;
void splitDate(int dayOfYear, int year, int *month, int *day);
int main()
{
int dayOfYear, year;
int *month, *day;
cout<<"Enter a day"<<endl;
cin>>dayOfYear;
cout<<"Enter a year"<<endl;
cin>>year;
splitDate(dayOfYear, year, month, day);
system("pause");
return 0;
}
void splitDate(int dayOfYear, int year, int *month, int *day)
{
if(dayOfYear >=1 || dayOfYear <= 31)
{
cout<<"month = 1"<<endl;
cout<<"day = "<<dayOfYear<<endl;
}
else if(dayOfYear >=32 || dayOfYear <= 70)
{
cout<<"month = 2"<<endl;
cout<<"day = "<<dayOfYear<<endl;
}
else if(dayOfYear >=71 || dayOfYear <= 101)
{
cout<<"month = 3"<<endl;
cout<<"day = "<<dayOfYear<<endl;
}
}