Hello.

Solved the problem and came across such an incomprehensible moment.

The condition of the problem is as follows: Write a program, according to the number of the student group, which determines the year of graduation. The group number is entered in the format A0209 - always one letter (Latin), then 4 digits (group number and year of receipt). Year must be printed in full; Consider working with groups that arrived in the 20th and 21st centuries.

Further, the problem was solved by me in this way:

int main() { time_t t; time(&t); int year=localtime(&t)->tm_year-100; int x; string god,grup,god1,god2; cout<<"Vvedite nazvanie gruppi: "; cin>>grup; god1 = grup[3] ; god2 = grup[4]; god = god1+god2; x = atoi(god.c_str()); if (x>year) { cout<<19<<x+6; } else { cout<<20<<x+6; } 

}

Everything works correctly, with the exception of the years 00, 01, 02, 03. When I enter these years, I’ll print out the graduation date with a three-digit number, that is, I enter 00, I get 206, and if I enter the year not from the above, everything is fine. For example, 07-2013, 75- 1981. And so on. So what is wrong here? )

    1 answer 1

    that is, I enter 00, accordingly I receive 206

    To print 6 as 06 (to get 2006):

     #include <iomanip> #include <iostream> int main() { int n = 6; std::cout << std::setfill('0') << std::setw(2) << n << std::endl; } 

    To avoid the program being dependent on the current time (cdd15 returns 1921 today, and in half a year it will return 2021), a fixed epoch can be used, for example: 1970, then сdd15 always corresponds to 2021:

     year = (x >= 70) ? 1900 + x : 2000 + x; graduation_year = year + 6; std::cout << graduation_year << std::endl; 

    At the same time, this fixes a bug with cdd99 (19105 - wrong, 2005 - correctly).