Reworked to better match other languages

This commit is contained in:
2020-08-28 14:28:20 -04:00
parent 3757e2169c
commit 03882a9366

View File

@@ -36,7 +36,6 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles
#include <cinttypes> #include <cinttypes>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include "Stopwatch.hpp"
#include "Problems/Problem19.hpp" #include "Problems/Problem19.hpp"
@@ -68,20 +67,26 @@ Problem19::DAYS Problem19::getDay(unsigned int month, unsigned int day, unsigned
} }
//Add the correct number of days for every month //Add the correct number of days for every month
while(currentMonth < month){ while(currentMonth < month){
//31 day months switch(currentMonth){
if(currentMonth == 2){ case 1:
if(isLeapYear(currentYear)){ case 3:
numDays += 29; case 5:
} case 7:
else{ case 8:
numDays += 28; case 10:
} case 12: numDays += 31; break;
} case 4:
else if((currentMonth == 1) || (currentMonth == 3) || (currentMonth == 5) || (currentMonth == 7) || (currentMonth == 8) || (currentMonth == 10) || (currentMonth == 12)){ case 6:
numDays += 31; case 9:
} case 11: numDays += 30; break;
else{ case 2:
numDays += 30; if(isLeapYear(currentYear)){
numDays += 29;
}
else{
numDays += 28;
}
break;
} }
++currentMonth; ++currentMonth;
} }