Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. class timecalcs {
  8. public:
  9. void agecalculator(){
  10. int year;
  11. int month;
  12. int day;
  13.  
  14.  
  15.  
  16. cout << "What is the current year?" << endl;
  17. cin >> year;
  18.  
  19.  
  20. cout << "What is the current month?" << endl;
  21. cin >> month;
  22.  
  23. cout << "What is the current day?" << endl;
  24. cin >> day;
  25.  
  26. cout << "Your current year is: ";
  27. cout << year;
  28. cout << "/";
  29. cout << month;
  30. cout << "/";
  31. cout << day << endl << endl;
  32.  
  33. int bornyear;
  34. int bornmonth;
  35. int bornday;
  36.  
  37. cout << "What year were you born in?" << endl;
  38. cin >> bornyear;
  39.  
  40. cout << "What month were you born in?" << endl;
  41. cin >> bornmonth;
  42.  
  43. cout << "What day were you born in?" << endl;
  44. cin >> bornday;
  45.  
  46. cout << "The date you were born is: ";
  47. cout << bornyear;
  48. cout << "/";
  49. cout << bornmonth;
  50. cout << "/";
  51. cout << bornday << endl;
  52.  
  53. //FUNCTIONS
  54.  
  55.  
  56. int numyear = 365;
  57. int numday = 1;
  58. int numjan = 31;
  59. int numfeb = 28;
  60. int nummar = 31;
  61. int numapr = 30;
  62. int nummaj = 31;
  63. int numjun = 30;
  64. int numjul = 31;
  65. int numaug = 31;
  66. int numsep = 30;
  67. int numoct = 31;
  68. int numnov = 30;
  69. int numdec = 31;
  70. int daycurrent;
  71. int dayborn;
  72. int dayremaincalc;
  73.  
  74. //daysumvv
  75.  
  76. daycurrent = day;
  77.  
  78. if (month == 1)
  79. {
  80. daycurrent = daycurrent + numjan;
  81.  
  82.  
  83. }
  84. if (month == 2)
  85. {
  86. daycurrent = daycurrent + numjan + numfeb;
  87.  
  88.  
  89. }
  90. if (month == 3)
  91. {
  92. daycurrent = daycurrent + numjan + numfeb + nummar;
  93.  
  94.  
  95. }
  96. if (month == 4)
  97. {
  98. daycurrent = daycurrent + numjan + numfeb + nummar + numapr;
  99.  
  100.  
  101. }
  102. if (month == 5)
  103. {
  104. daycurrent = daycurrent + numjan + numfeb + nummar + numapr + nummaj;
  105.  
  106.  
  107. }
  108. if (month == 6)
  109. {
  110. daycurrent = daycurrent + numjan + numfeb + nummar + numapr + nummaj + numjun;
  111.  
  112.  
  113. }
  114. if (month == 7)
  115. {
  116. daycurrent = daycurrent + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul;
  117.  
  118.  
  119. }
  120. if (month == 8)
  121. {
  122. daycurrent = daycurrent + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug;
  123.  
  124.  
  125. }
  126. if (month == 9)
  127. {
  128. daycurrent = daycurrent + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep;
  129.  
  130.  
  131. }
  132. if (month == 10)
  133. {
  134. daycurrent = daycurrent + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep + numoct;
  135.  
  136.  
  137. }
  138. if (month == 11)
  139. {
  140. daycurrent = daycurrent + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep + numoct + numnov;
  141.  
  142.  
  143. }
  144. if (month == 12)
  145. {
  146. daycurrent = daycurrent + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep + numoct + numnov + numdec;
  147.  
  148.  
  149. }
  150. daycurrent = daycurrent + (year * numyear);
  151.  
  152. dayborn = bornday;
  153.  
  154. if (bornmonth == 1)
  155. {
  156. dayborn = dayborn + numjan;
  157. dayremaincalc = numjan;
  158.  
  159. }
  160. if (bornmonth == 2)
  161. {
  162. dayborn = dayborn + numjan + numfeb;
  163. dayremaincalc = numfeb;
  164.  
  165. }
  166. if (bornmonth == 3)
  167. {
  168. dayborn = dayborn + numjan + numfeb + nummar;
  169. dayremaincalc = nummar;
  170.  
  171. }
  172. if (bornmonth == 4)
  173. {
  174. dayborn = dayborn + numjan + numfeb + nummar + numapr;
  175. dayremaincalc = numapr;
  176.  
  177. }
  178. if (bornmonth == 5)
  179. {
  180. dayborn = dayborn + numjan + numfeb + nummar + numapr + nummaj;
  181. dayremaincalc = nummaj;
  182.  
  183. }
  184. if (bornmonth == 6)
  185. {
  186. dayborn = dayborn + numjan + numfeb + nummar + numapr + nummaj + numjun;
  187. dayremaincalc = numjun;
  188.  
  189. }
  190. if (bornmonth == 7)
  191. {
  192. dayborn = dayborn + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul;
  193. dayremaincalc = numjul;
  194.  
  195. }
  196. if (bornmonth == 8)
  197. {
  198. dayborn = dayborn + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug;
  199. dayremaincalc = numaug;
  200.  
  201. }
  202. if (bornmonth == 9)
  203. {
  204. dayborn = dayborn + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep;
  205. dayremaincalc = numsep;
  206.  
  207. }
  208. if (bornmonth == 10)
  209. {
  210. dayborn = dayborn + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep + numoct;
  211. dayremaincalc = numoct;
  212.  
  213. }
  214. if (bornmonth == 11)
  215. {
  216. dayborn = dayborn + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep + numoct + numnov;
  217. dayremaincalc = numnov;
  218.  
  219. }
  220. if (bornmonth == 12)
  221. {
  222. dayborn = dayborn + numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep + numoct + numnov + numdec;
  223. dayremaincalc = numdec;
  224.  
  225. }
  226.  
  227.  
  228. dayborn = dayborn + (bornyear * numyear);
  229.  
  230. //daysum ^^
  231.  
  232. //daycurrent = days from 0 to now.
  233. //dayborn = days from 0 to birthdate
  234. //now subtraction and convertion
  235.  
  236. int bornsum = daycurrent - dayborn;
  237. int bornsumcopy = daycurrent - dayborn;
  238. int yeargive;
  239. int monthgive;
  240.  
  241. monthgive = 0;
  242.  
  243.  
  244. if (bornsum >= 365)
  245. {
  246. yeargive = 1;
  247. bornsum = bornsum - 365;
  248. }
  249. if (bornsum >= 365)
  250. {
  251. yeargive = yeargive + 1 * ((bornsumcopy / 365) - 1);
  252. bornsum = bornsum - 365 * ((bornsumcopy / 365) - 1);
  253. }
  254. if (bornsum >= 365){
  255. yeargive = yeargive + 1;
  256. bornsum = bornsum - 365;
  257. }
  258. if (bornsum >= 365){
  259. yeargive = yeargive + 1;
  260. bornsum = bornsum - 365;
  261. }
  262.  
  263.  
  264. if (numfeb + numjan > bornsum && bornsum > numjan)
  265. {
  266. bornsum = bornsum - numjan;
  267. monthgive = 1;
  268. }
  269. if (nummar + numfeb + numjan > bornsum && bornsum > numjan + numfeb)
  270. {
  271. bornsum = bornsum - numjan - numfeb;
  272. monthgive = 2;
  273. }
  274. if ((nummar + numfeb + numjan + numapr) > bornsum && bornsum > nummar + numfeb + numjan)
  275. {
  276. bornsum = bornsum - numjan - numfeb - nummar;
  277. monthgive = 3;
  278. }
  279. if (nummar + numfeb + numjan + numapr + nummaj > bornsum && bornsum > numjan + numfeb + nummar + numapr)
  280. {
  281. bornsum = bornsum - numjan - numfeb - nummar - numapr;
  282. monthgive = 4;
  283. }
  284. if (nummar + numfeb + numjan + numapr + nummaj + numjun > bornsum && bornsum > numjan + numfeb + nummar + numapr + nummaj)
  285. {
  286. bornsum = bornsum - numjan - numfeb - nummar - numapr - nummaj;
  287. monthgive = 5;
  288. }
  289. if (nummar + numfeb + numjan + numapr + nummaj + numjun + numjul > bornsum && bornsum > numjan + numfeb + nummar + numapr + nummaj + numjun)
  290. {
  291. bornsum = bornsum - numjan - numfeb - nummar - numapr - nummaj - numjun;
  292. monthgive = 6;
  293. }
  294. if (nummar + numfeb + numjan + numapr + nummaj + numjun + numjul + numaug > bornsum && bornsum > numjan + numfeb + nummar + numapr + nummaj + numjun + numjul)
  295. {
  296. bornsum = bornsum - numjan - numfeb - nummar - numapr - nummaj - numjun - numjul;
  297. monthgive = 7;
  298. }
  299. if (nummar + numfeb + numjan + numapr + nummaj + numjun + numjul + numaug + numsep > bornsum && bornsum > numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug)
  300. {
  301. bornsum = bornsum - numjan - numfeb - nummar - numapr - nummaj - numjun - numjul - numaug;
  302. monthgive = 8;
  303. }
  304. if (nummar + numfeb + numjan + numapr + nummaj + numjun + numjul + numaug + numsep + numoct > bornsum && bornsum > numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep)
  305. {
  306. bornsum = bornsum - numjan - numfeb - nummar - numapr - nummaj - numjun - numjul - numaug - numsep;
  307. monthgive = 9;
  308. }
  309. if (nummar + numfeb + numjan + numapr + nummaj + numjun + numjul + numaug + numsep + numoct + numnov > bornsum && bornsum > numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep + numoct)
  310. {
  311. bornsum = bornsum - numjan - numfeb - nummar - numapr - nummaj - numjun - numjul - numaug - numsep - numoct;
  312. monthgive = 10;
  313. }
  314. if (nummar + numfeb + numjan + numapr + nummaj + numjun + numjul + numaug + numsep + numoct + numnov + numdec > bornsum && bornsum > numjan + numfeb + nummar + numapr + nummaj + numjun + numjul + numaug + numsep + numoct + numnov)
  315. {
  316. bornsum = bornsum - numjan - numfeb - nummar - numapr - nummaj - numjun - numjul - numaug - numsep - numoct - numnov;
  317. monthgive = 11;
  318. }
  319.  
  320.  
  321. int daysleft;
  322. int monthsleft;
  323. int nextage;
  324.  
  325. monthsleft = ((monthgive - 12) * (-1)) - 1;
  326. daysleft = dayremaincalc - bornsum ;
  327. nextage = yeargive + 1;
  328.  
  329. cout << "You are: " << yeargive << ", " << monthgive << " months and " << bornsum << " days" << endl;
  330.  
  331. cout << "Theres ";
  332. cout << monthsleft;
  333. cout << " months and ";
  334. cout << daysleft;
  335. cout << " days before your next birthday where you will be " << nextage << endl;
  336. cout << "This code was written by Valde" << endl << endl;
  337.  
  338. Sleep(100);
  339.  
  340. int menuagecalc;
  341. cout << "1 for agecalculator. \n2 for current year calculator. \n3 for birthdat calculator.\nEnter another number to exit.\n\nEnter your choice here: ";
  342. cin >> menuagecalc;
  343. cout << "" << endl;
  344.  
  345. if (3 >= menuagecalc && menuagecalc >= 1) {
  346. if (menuagecalc == 1){
  347. timecalcs timcalcobject;
  348. timcalcobject.agecalculator();
  349. }
  350.  
  351. if (menuagecalc == 2){
  352. timecalcs timcalcobject;
  353. timcalcobject.currentyearcalculator();
  354. }
  355.  
  356. if (menuagecalc == 3){
  357. timecalcs timcalcobject;
  358. timcalcobject.birthdatecalculator();
  359. }
  360. }
  361. else {
  362. cout << "Exiting." << endl;
  363. exit(0);
  364. }
  365.  
  366.  
  367. }
  368. void currentyearcalculator(){
  369.  
  370. int birthyear;
  371. int currentageyear;
  372. int year;
  373. int birthdayyet;
  374.  
  375. cout << "What year were you born?" << endl;
  376. cin >> birthyear;
  377.  
  378. cout << "\nWhat is your current age?" << endl;
  379. cin >> currentageyear;
  380.  
  381. cout << "\nHave you had your birthday this year? 1/2 (1=yes, 2=no)" << endl;
  382. cin >> birthdayyet;
  383.  
  384. year = currentageyear + birthyear;
  385. if (birthdayyet == 2)
  386. {
  387. year = year + 1;
  388. }
  389.  
  390.  
  391. cout << "\n\nThe current year is either " << year << " or one year more." << endl;
  392. }
  393. void birthdatecalculator(){
  394.  
  395. int currentyear;
  396. int currentmonth;
  397. int currentday;
  398. int myageyear;
  399. int myagemonth;
  400. int myageday;
  401.  
  402. cout << "What is the current year?" << endl;
  403. cin >> currentyear;
  404.  
  405. cout << "\n\nWhat is the current month?" << endl;
  406. cin >> currentmonth;
  407.  
  408. cout << "\n\nWhat is the current day?" << endl;
  409. cin >> currentday;
  410.  
  411. cout << "\n\nWhat is your current age in years?" << endl;
  412. cin >> myageyear;
  413.  
  414. cout << "\n\nHow many months into your age?" << endl;
  415. cin >> myagemonth;
  416.  
  417. cout << "\n\nHow many days into your age, don't wright months." << endl;
  418. cin >> myageday;
  419.  
  420. int resultday;
  421. int resultmonth;
  422. int resultyear;
  423.  
  424. resultday = currentday - myageday;
  425. resultmonth = currentmonth - myagemonth;
  426. resultyear = currentyear - myageyear;
  427.  
  428. if (resultday < 0)
  429. {
  430. resultmonth = resultmonth + 1;
  431. resultday = resultday + 30;
  432.  
  433. }
  434.  
  435. if (resultmonth < 0)
  436. {
  437. resultyear = resultyear + 1;
  438. resultmonth = resultmonth + 12;
  439. }
  440.  
  441. cout << "This is the date you were born aprox: " << resultyear << "/" << resultmonth << "/" << resultday << endl;
  442.  
  443. }
  444. };
  445.  
  446.  
  447.  
  448. int menue()
  449. {
  450.  
  451.  
  452. int menu;
  453. cout << "1 for agecalculator. \n2 for current year calculator. \n3 for birthdat calculator.\nEnter another number to exit.\n\nEnter your choice here: ";
  454. cin >> menu;
  455. cout << "" << endl;
  456.  
  457. if (3 >= menu && menu >= 1) {
  458. if (menu == 1){
  459. timecalcs timcalcobject;
  460. timcalcobject.agecalculator();
  461. }
  462.  
  463. if (menu == 2){
  464. timecalcs timcalcobject;
  465. timcalcobject.currentyearcalculator();
  466. }
  467.  
  468. if (menu == 3){
  469. timecalcs timcalcobject;
  470. timcalcobject.birthdatecalculator();
  471. }
  472. }
  473. else {
  474. cout << "Exiting." << endl;
  475. exit(0);
  476. }
  477.  
  478. system("pause");
  479. return 0;
  480.  
  481. }
  482.  
  483.  
  484. int main()
  485. {
  486. menue();
  487.  
  488. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement