everything works fine except when the switch is false and immediate closes the prompt how do i fix than and also how do i fix default it doesn't work properly
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
// Function declaration:
int serial_julian_date(int Month, int Day, int Year);
int serial_2_month(int nDate);
int serial_2_day(int nDate);
int serial_2_year(int nDate);
bool is_leap_year(int Year);
// Main fuction with loop
int main()
{
int Month = 1;
int Day = 1;
int Year = 1;
cout << " Enter a date in MM DD YYYY format (separated by spaces): ";
cin >> Month >> Day >> Year;
bool is_leap_year(int Year);
bool validate_mm_dd_yyyy(int Month, int Day, int Year);
{
switch (Month){
case 1:
if (Day >= 32) return false;
break;
case 3:
if (Day >= 32) return false;
break;
case 5:
if (Day >= 32) return false;
break;
case 7:
if (Day >= 32) return false;
break;
case 8:
if (Day >= 32) return false;
break;
case 10:
if (Day >= 32) return false;
break;
case 12:
if (Day >= 32) return false;
break;
case 4:
if (Day >= 31) return false;
break;
case 6:
if (Day >= 31) return false;
break;
case 9:
if (Day > 31) return false;
break;
case 11:
if (Day > 31) return false;
break;
case 2:
if (Day > 28 + is_leap_year(Year)) return false;
break;
default:
cout << "Enter a usable Date to Month";
break;
return true;
}
int nDate = serial_julian_date(Month, Day, Year);
if (Month > 12)
cout << "Enter a usable month" << '\n';
if ((Month <= 12)
&&
(Day = true))
cout << "Serial Julian date is:" << nDate << "\n";
if ((Month <= 12)
&&
(Day = true))
cout << "Back to Gregorian date: " << serial_2_month(nDate) << "/" << serial_2_day(nDate) << "/" << serial_2_year(nDate) << "\n";
system("pause");
}
int nDate = serial_julian_date(Month, Day, Year);
while (nDate != 0)
{
cout << " Enter a date in MM DD YYYY format (separated by spaces): " "\n";
cout << "Enter 0 for MM DD YYYY format to exit (separated by spaces):" "\n";
cin >> Month >> Day >> Year;
bool validate_mm_dd_yyyy(int Month, int Day, int Year);
bool is_leap_year(int Year);
{
if (Month < 1 || Month > 12) return false;
switch (Month){
case 1:
if (Day >= 32) return false;
break;
case 3:
if (Day >= 32) return false;
break;
case 5:
if (Day >= 32) return false;
break;
case 7:
if (Day >= 32) return false;
break;
case 8:
if (Day >= 32) return false;
break;
case 10:
if (Day >= 32) return false;
break;
case 12:
if (Day >= 32) return false;
break;
case 4:
if (Day >= 31) return false;
break;
case 6:
if (Day >= 31) return false;
break;
case 9:
if (Day > 31) return false;
break;
case 11:if (Day > 31) return false;
break;
case 2:
if (Day > 28 + is_leap_year(Year)) return false;
break;
default:
cout << "Enter correct day corresponding to month" << '\n';
return true;
}
}
int nDate = serial_julian_date(Month, Day, Year);
if (Month > 12)
cout << "Enter a usable month" << '\n';
if (Month < 1, Day < 1, Year < 1)
break;
if (Month <= 12)
cout << "Serial Julian date is:" << nDate << "\n";
if (Month <= 12)
cout << "Back to Gregorian date: " << serial_2_month(nDate) << "/" << serial_2_day(nDate) << "/" << serial_2_year(nDate) << "\n";
system("pause");
return 0;
}
while (nDate != 0)
{
cout << " Enter a date in MM DD YYYY format (separated by spaces): " "\n";
cout << "Enter 0 for MM DD YYYY format to exit (separated by spaces):" "\n";
cin >> Month >> Day >> Year;
if (Month < 1 && Day < 1 && Year < 1)
break;
cout << " Enter a date in MM DD YYYY format (separated by spaces): ";
cin >> Month >> Day >> Year;
int nDate = serial_julian_date(Month, Day, Year);
if (Month > 12)
cout << "Enter a usable month" << '\n';
if (Month <= 12)
cout << "Serial Julian date is:" << nDate << "\n";
if (Month <= 12)
cout << "Back to Gregorian date: " << serial_2_month(nDate) << "/" << serial_2_day(nDate) << "/" << serial_2_year(nDate) << "\n";
system("pause");
}
}
// Function definition:
int serial_julian_date(int Month, int Day, int Year)
{
int a = (14 - Month) / 12;
int m = Month + (12 * a) - 3;
int y = Year + 4800 - a;
int nDate = Day + ((153 * m) + 2) / 5 + (365 * y) + (y / 4) - (y / 100) + (y / 400) - 32045;
return nDate;
}
int serial_2_month(int nDate)
{
int a = nDate + 32044;
int b = (4 * a + 3) / 146097;
int c = a - ((146097 * b) / 4);
int d = (4 * c + 3) / 1461;
int e = c - (1461 * d / 4);
int m = (5 * e + 2) / 153;
int Month = m + 3 - (12 * (m / 10));
return Month;
}
int serial_2_day(int nDate)
{
int a = nDate + 32044;
int b = (4 * a + 3) / 146097;
int c = a - ((146097 * b) / 4);
int d = (4 * c + 3) / 1461;
int e = c - (1461 * d / 4);
int m = (5 * e + 2) / 153;
int Day = e - ((153 * m) + 2) / 5 + 1;
return Day;
}
int serial_2_year(int nDate)
{
int a = nDate + 32044;
int b = (4 * a + 3) / 146097;
int c = a - ((146097 * b) / 4);
int d = (4 * c + 3) / 1461;
int e = c - (1461 * d / 4);
int m = (5 * e + 2) / 153;
int Year = (100 * b) + d - 4800 + (m / 10);
return Year;
}