I want to find the number of days between two months. I use Xcode but don't want to go through the trouble of installing boost or 'date.h', so I tried to do it more primitively but somehow the code keeps breaking at a certain point:
for ( it=mymap.begin() ; it != mymap.end(); it++ ) {
auto nx = next(it);
if (it->second.patientID == nx->second.patientID) {
//31 28 31 30 31 30 31 31 30 31 30 31
yue = it->second.month;
yue2 = nx->second.month;
sincejan1 = 0;
sincejan = 0;
//it keeps breaking at the line below
if (abs(yue-yue2) > 0) {
if (yue ==12)
sincejan1 = 365-31;
if (yue ==11)
sincejan1 = 365-31-30;
if (yue ==10)
sincejan1 = 365-31-30-31;
if (yue ==9)
sincejan1 = 365-31-30-31-30;
if (yue ==8)
sincejan1 = 31+28+31+30+31+30+31+31;
if (yue ==7)
sincejan1 = 31+28+31+30+31+30+31;
if (yue ==6)
sincejan1 = 31+28+31+30+31+30;
if (yue ==5)
sincejan1 = 31+28+31+30+31;
if (yue ==4)
sincejan1 = 31+28+31+30;
if (yue ==3)
sincejan1 = 31+28+31;
if (yue ==2)
sincejan1 = 31+28;
if (yue ==1)
sincejan1 = 31;
if (yue2 ==12)
sincejan = 365-31;
if (yue2 ==11)
sincejan = 365-31-30;
if (yue2 ==10)
sincejan = 365-31-30-31;
if (yue2 ==9)
sincejan = 365-31-30-31-30;
if (yue2 ==8)
sincejan = 31+28+31+30+31+30+31+31;
if (yue2 ==7)
sincejan = 31+28+31+30+31+30+31;
if (yue2 ==6)
sincejan = 31+28+31+30+31+30;
if (yue2 ==5)
sincejan = 31+28+31+30+31;
if (yue2 ==4)
sincejan = 31+28+31+30;
if (yue2 ==3)
sincejan = 31+28+31;
if (yue2 ==2)
sincejan = 31+28;
if (yue2 ==1)
sincejan = 31;
}
monthDiff = sincejan1 - sincejan;
}
}
I'm not sure what's wrong or if this is an okay way to do this. I would appreciate greatly any help/advice! I'm a programming beginner.