As Part of an assignment one of the requirments is to convert a date into month format. that is the user must enter start month and year of employment and end month and year of employment for example 4 1980 till 7 2009 (mmyyy)
these two dates must be coverted to months easy enough. Then those months need to converted back to years and months worked in this case it will work out to 28 years and 4 months. I have busted my head trying to get this right and for most it works but if i use a date such as 1 2003 till 12 2004 the output isnt correct. i dont know what im doing wrong as the formulas i made up seem legit on paper but not on program yet its basic addition subtraction and multiplication.
Could someone please assist me with finding my fault. code attempt below
#include <iostream>
#include <assert.h>
using namespace std;
int main()
{
int smnt;
int syear;
int emnt;
int eyear;
int ty;
int tm;
int GetMonths;
//int pension;
// int calcty;
int ConvertBacktoYears;
int TotalYearsToMonths;
int TotalYearsAndMonths;
cout << "Please enter the first month of employment" << endl;
cin >> smnt;
//assert month sm>0 & sm<13
assert(smnt>0 && smnt<13);
cout << "Please enter the year you started work" << endl;
cin >> syear;
//assert syear
assert(syear>1974 && syear<2011);
// check what values where entered for start of employment
//cout << (smnt)<<" and "<<(syear) << endl;
cout << "Please enter the last month of employment " << endl;
cin >> emnt;
//assert month em>0 & em<13
assert(emnt>0 && emnt<13);
cout << "Please enter the last year of employment" << endl;
cin >> eyear;
// assert eyear
assert(eyear>1974 && eyear<2011);
// check what values where entered for end of employment
//cout << (emnt)<<" and "<<(eyear) << endl;
ty = eyear-syear;
TotalYearsToMonths = (ty*12);
tm = ((12-(smnt- 1)) + emnt);
TotalYearsAndMonths = ((TotalYearsToMonths- (smnt)- (12-emnt))+tm);
ConvertBacktoYears = (TotalYearsAndMonths/12);
GetMonths = TotalYearsAndMonths-(ConvertBacktoYears *12);
cout<< " years " <<ConvertBacktoYears<< " months "<< GetMonths<< endl;
return 0;
}