[Solved] So close.. Determining age via current date and user input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

[Solved] So close.. Determining age via current date and user input

I made a class that uses <ctime> to get the current date. I also use <sstream> to reformat the user inputted birthday (MM/DD/YYYY). I am getting an output but I don't believe I am using ctime correctly.. Any help? Please check attached code. Thank you! https://code.sololearn.com/ctV45MQa0b79/?ref=app

11th Sep 2018, 8:30 AM
Philip
Philip - avatar
1 Answer
+ 1
Thank you so much for taking the time to go through my code, extremely helpful!! This has been the most difficult code I've attempted since I started learning with SoloLearn almost 3 weeks ago, so I was unsure if I could even get this to start compiling from concept stages, but your notes will help me take it to the next level :) Will update later today when I have time. EDIT: I fixed it! I did have to adjust the logic for calculating age to this: age = -1; currentDate(); if(currentMonth >= month){ if(currentMonth == month){ if(currentDay >= day){ age = currentYear - year; } } else if (currentMonth > month){ age = currentYear - year; } } if(age == -1) age = currentYear - year - 1; Thank you again for your help.
11th Sep 2018, 4:43 PM
Philip
Philip - avatar