Skip to content

Instantly share code, notes, and snippets.

@ShaneRich5
Created October 15, 2020 19:10
Show Gist options
  • Save ShaneRich5/d302c24151c1a4c834a1f586c9360778 to your computer and use it in GitHub Desktop.
Save ShaneRich5/d302c24151c1a4c834a1f586c9360778 to your computer and use it in GitHub Desktop.
Assignment
#include <iostream>
using namespace std;
//enum Months { Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,Dec};
char skip;
char response;
int m = 0, d = 0, y = 0;
int OrdDay = 0, priorDays = 0;
bool IsLeapYear(int y, int priorDays)
{
if (y % 100 != 0 && y % 4 == 0 || y % 400 == 0)
return true;
return false;
};
int OrdinalDay(int m, int d, int priorDays) { OrdDay = d + priorDays; return priorDays;} //if (IsLeapYear) { priorDays + 1; }; return priorDays + 1; }
void ReadDate(int& m, int d, int& priorDays) {
if (m == 1)
priorDays = 0, d < 32; else
if (m == 2)
priorDays = 31, d < 30; else
if (m == 3)
priorDays = 59, d < 32; else
if (m == 4)
priorDays = 90, d < 31; else
if (m == 5)
priorDays = 120, d < 32; else
if (m == 6)
priorDays = 151, d < 31; else
if (m == 7)
priorDays = 181, d < 32; else
if (m == 8)
priorDays = 212, d < 32; else
if (m == 9)
priorDays = 243, d < 31; else
if (m == 10)
priorDays = 273, d < 32; else
if (m == 11)
priorDays = 304, d < 31; else
if (m == 12)
priorDays = 334, d <= 32;
}
int main()
{
cout << "Would you like to convert a date to Ordinal Format (Y/N)? ";
cin >> response;
while (response != 'y' && response != 'Y' && response != 'n' && response != 'N') {
cout << "\nInvalid response, please enter Y or N: ";
cin >> response;
}
while (response == 'y' || response == 'Y') {
cout << "\nInput a Date in MM/DD/YYYY format to be converted into Ordinal form: ";
cin >> m >> skip >> d >> skip >> y;
while (m < 1 || m > 12 || d < 1 || d > 31) {
cout << "invalid date Range, Please enter Date it MM/DD/YYYY format: ";
cin >> m >> skip >> d >> skip >> y;
}
ReadDate(m, d, priorDays);
IsLeapYear(y, priorDays + 1);
OrdinalDay(m, d, priorDays);
cout << "The Date you entered in Ordinal form is " << y << " - " << OrdDay << endl;
do {
cout << "\nWould you like to convert another date to Ordinal format? (Y/N): ";
cin >> response;
} while (response != 'y' && response != 'Y'
&& response != 'n' && response != 'N');
}
return 0;
/*return IsLeapYear(y, priorDays);
if (IsLeapYear)
{
priorDays++;
};*/
/*bool IsLeapYear(int y, int priorDays)
bool isLeapYear = false;
if (y % 4 == 0) {
if (y % 100 == 0) {
if (y % 400 == 0) {
isLeapYear = true;
}
}
else isLeapYear = true;
}
return priorDays++;*/
}
@Simply-fatal
Copy link

My issues (I have a lot but for the sake of time):

  1. I have no idea how to make the bool “IsLeapYear” work and add 1 Day to March to represent a leap year

  2. For “readDate” I don’t know how to put a limit on the days in the months. Ex: April has only 30 days but the user can put 31 and no error shows up.

  3. Also I may not see it but I want to know if the bool Isleapyear accurate in calculating a leap year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment