1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <string>
int main()
{
const short endmonth[13] = {1,31,59,90,120,151,181,212,243,273,304,334,365};
const std::string months[12] = {"January","February","March","April",
"May","June","July", "August", "September",
"October","November", "December"};
short d = 0;
std::cout << "Enter a day within the year" << std::endl;
std::cin >> d;
while (d < 1 || d > 365)
{
std::cout << "Invalid input. Please Enter a number within 1-365" << std::endl;
std::cin >> d;
}
for(int i = 0; i < 12; ++i)
{
if(d >= endmonth[i] && d <= endmonth[i + 1])
{
std::cout << "Month is:" << months[i] << std::endl;
break;
}
}
return 0;
}
|