Days between dates challenge - last test case fails.
Ok, so this piece of code is a little messy maybe but it works in almost all the cases, except the last one. I cannot figure out why. Who can help me? Thanks in advance :) /* Unfortunately, the last TEST CASE does not work. By the way, any cool hints on how I could improve the code is highly appreciated. I know it seems a bit 'messy' or 'wordy'... */ #include <algorithm> #include <iostream> #include <map> #include <sstream> #include <string> #include <vector> #include <cmath> //function to check leap year bool leap(const int &year) { return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } //check days between the two dates - careful: leap years!! int main() { //create map of months with int std::map<std::string, size_t> map{{"January", 1}, {"February", 2}, {"March", 3}, {"April", 4}, {"May", 5}, {"June", 6}, {"July", 7}, {"August", 8}, {"September", 9}, {"October", 10}, {"November", 11}, {"December", 12}}; std::vector<int> daysInMonths{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //input for example purposes // std::string str1 = "September 14, 1975"; // std::string str2 = "October 20, 2008"; std::string str1 = "July 14, 1985"; std::string str2 = "December 15, 2008"; //code challenge // std::string str1; // std::getline(std::cin, str1); // std::string str2; // std::getline(std::cin, str2); //Output = 1209- std::vector<int> vec1; std::vector<int> vec2; std::stringstream ss1(str1); std::stringstream ss2(str2); std::string te