fork download
  1. //function copyrighted by LG (ESSEC Advanced Master In Financial Techniques: Financial Markest and
  2. //Investment Valuation), in the near future vote for me to become president and add me on facebook
  3. //to be recruited in the new government if you want to compute pragmatic solutions for higher life standards
  4. //Date format: ex string date1="01/02"; string date2="06/03"; the difference in between date1 and date2
  5. //has to be under 360 days for financial purposes. Feel free to ask questions on my new facebook:
  6. //https://w...content-available-to-author-only...k.com/ludo.giraud.7 . To access datedifference:
  7. //int ddif=checkvaliddatedifference("01/02", "26/04")[2];
  8.  
  9. string inttostring(int anint)
  10. {
  11. std::ostringstream sstream;
  12. sstream << afloat;
  13. std::string astring= sstream.str();
  14. return astring;
  15. }
  16.  
  17. template <class T> bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&))
  18. {
  19. std::istringstream iss(s);
  20. return !(iss >> f >> t).fail();
  21. }
  22.  
  23.  
  24. vector<int> checkvaliddatedifference(string date1, string date2)
  25. {
  26. vector<int> doublebull(3);
  27. int bull=0;
  28. int bull2=0;
  29. int dif;
  30. string date1daystring,date1monthstring,date2daystring,date2monthstring;
  31. float date1dayfloat, date2dayfloat,date1monthfloat,date2monthfloat;
  32. date1daystring=date1;
  33. date1monthstring=date1;
  34. date2daystring=date2;
  35. date2monthstring=date2;
  36. date1daystring.erase(date1daystring.begin()+2,date1daystring.end());
  37. date1monthstring.erase(date1monthstring.begin(),date1monthstring.begin()+3);
  38. date2daystring.erase(date2daystring.begin()+2,date2daystring.end());
  39. date2monthstring.erase(date2monthstring.begin(),date2monthstring.begin()+3);
  40. from_string<float>(date1dayfloat,date1daystring,std::hex);
  41. from_string<float>(date2dayfloat,date2daystring,std::hex);
  42. from_string<float>(date1monthfloat,date1monthstring,std::hex);
  43. from_string<float>(date2monthfloat,date2monthstring,std::hex);
  44. map<string, int> Calendar;
  45. Calendar["01"]=31;
  46. Calendar["02"]=28;
  47. Calendar["03"]=31;
  48. Calendar["04"]=30;
  49. Calendar["05"]=31;
  50. Calendar["06"]=30;
  51. Calendar["07"]=31;
  52. Calendar["08"]=31;
  53. Calendar["09"]=30;
  54. Calendar["10"]=31;
  55. Calendar["11"]=30;
  56. Calendar["12"]=31;
  57.  
  58. int daysd1untilendofmonth;
  59. int tempint;
  60. tempint=Calendar[date1monthstring];
  61. daysd1untilendofmonth=tempint-int(date1dayfloat);
  62.  
  63.  
  64. if (date1monthfloat<date2monthfloat)
  65. {
  66. bull=1;
  67. }
  68. if (date1monthfloat==date2monthfloat&&date1dayfloat<date2dayfloat)
  69. {
  70. if (date2dayfloat-date1dayfloat>4)
  71. {
  72. bull=1;
  73. }
  74. else
  75. {
  76. bull=0;
  77. }
  78. }
  79.  
  80. if (date1monthfloat>date2monthfloat||date1monthfloat==date2monthfloat&&date1dayfloat>date2dayfloat)
  81. {
  82. if(date1dayfloat>date2dayfloat)
  83. {
  84. bull2=1;
  85. }
  86. else
  87. {
  88. bull2=0;
  89. }
  90.  
  91. int countt=0;
  92. int monthbool=1;
  93. string newmonth;
  94. int days=daysd1untilendofmonth;
  95. float date1monthfloatinit=date1monthfloat;
  96. if (date1monthfloat==date2monthfloat)
  97. {
  98.  
  99. monthbool=0;
  100. }
  101.  
  102. date1monthfloat++;
  103. if (date1monthfloat==13)
  104. {
  105. date1monthfloat=1;
  106. }
  107. while(date2monthfloat!=date1monthfloat)
  108. {
  109. countt++;
  110. if (monthbool==1)
  111. {
  112. date1monthfloat++;
  113. }
  114. if (monthbool==0);
  115. {
  116. monthbool=1;
  117. }
  118.  
  119. if (date1monthfloat==13)
  120. {
  121. date1monthfloat=1;
  122. }
  123. if (date1monthfloat<10);
  124. {
  125. newmonth="0"+inttostring(int(date1monthfloat));
  126. }
  127. if (date1monthfloat>9)
  128. {
  129. newmonth=inttostring(int(date1monthfloat));
  130. }
  131. days=days+Calendar[newmonth];
  132. };
  133. if (countt>0)
  134. {
  135. days=days-Calendar[newmonth]+date2dayfloat;
  136. }
  137. else days= Calendar[inttostring(int(date1monthfloatinit))]-int(date1dayfloat)+date2dayfloat;
  138. if (days>360)
  139. {
  140. bull=0;
  141. }
  142. else bull=1;
  143. }
  144. triplebull[0]=bull;
  145. triplebull[1]=bull2;
  146. triplebull[2]=days;
  147.  
  148. return triplebull;;
  149. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9: error: ‘string’ does not name a type
prog.cpp:17: error: expected unqualified-id before ‘&’ token
prog.cpp:17: error: expected ‘,’ or ‘...’ before ‘&’ token
prog.cpp: In function ‘bool from_string(T&)’:
prog.cpp:19: error: ‘istringstream’ is not a member of ‘std’
prog.cpp:19: error: expected `;' before ‘iss’
prog.cpp:20: error: ‘iss’ was not declared in this scope
prog.cpp:20: error: ‘f’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:24: error: expected constructor, destructor, or type conversion before ‘<’ token
stdout
Standard output is empty