Hello, I’ve started recently to learn C++ programming. And this is the first program I write in this awesome language:
// my first program in C++ #include <iostream> using namespace std; int main() { time_t theTime = time(NULL); struct tm *aTime = localtime(&theTime); int currentday = aTime->tm_mday; int currentmonth = aTime->tm_mon + 1; int currentyear = aTime->tm_year + 1900; int day; int month; int year; cout << "Please enter your year of born: "; cin >> year; cout << "Please enter your month of born: "; cin >> month; cout <<"Please enter your day of born: "; cin >> day; cout << "You are: "; if (currentday < day) { currentmonth=currentmonth-1; currentday=currentday+30; cout << currentday-day << " days and "; } else { cout << currentday-day << " days and "; } if (currentmonth < month) { currentyear=currentyear-1; currentmonth=currentmonth+12; cout << currentmonth-month << " months and "; } else { cout << currentmonth-month << " months and "; } cout << currentyear-year << " years old\n"; }
Very simple I know, but it should be a good start for me to look forward in coding something better in C++. Maybe starting a project who knows? 😀
See ya!
Doesn’t seem to compile in Visual Studio. Did you forget to include a library maybe?
It compiles fine on g++, maybe Visual Studio Requires additional code or including some libraries.
What’s the issued error?
You forgot to include the
Ugh this web site you forgot the include the ctime library
I don’t know really what’s going on 😀
but maybe it’s a compiler issue, because in g++ it compile fine here.
Are you using a different compiler?