Hi i need help, this program meant to take date by integer numbers check if the date is valid and return a date with month written in a word if it's not valid date the program should stop and exit
#include <iostream>
using namespace std;
int main()
#include<iostream>
bool ValidMonth(int month)
{
bool rtn(false);
if ((month >= 1) && month <= 12)
{
rtn = true;
}
return rtn;
}
bool validDay(int day, int month)
{
bool rtn(false);
// NOTE: i don't know how many days are in each month, but this is the kinda way you might wanna go about it
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
if (day>=1 && day <=31)
{
rtn = true;
}
break;
case 2:
if (day >= 1 && day <= 28) // or 29 if leap
{
rtn = true;
}
break;
default:
// whatever
break;
}
return rtn;
}
bool validYear(int year)
{
bool rtn(false);
if (year >= 0 && year <= 3000)
{
rtn = true;
}
return rtn;
}
int main()
{
int day, month, year;
std::cout << "enter day\n";
std::cin >> day;
std::cout << "enter month\n";
std::cin >> month;
std::cout << "enter year\n";
std::cin >> year;
if (validDay(day, month) && ValidMonth(month) && validYear(year))
{
// do your switch for the month as you are doing
}
}
NOTE: i haven't completed the logic for how many days in the month of interest, but you get the idea.