Skip to content

Instantly share code, notes, and snippets.

@mshafae
Last active December 13, 2023 23:15
Show Gist options
  • Save mshafae/440681ee258659c96d40eb9eb60b14e5 to your computer and use it in GitHub Desktop.
Save mshafae/440681ee258659c96d40eb9eb60b14e5 to your computer and use it in GitHub Desktop.
Calculate your age using a constant current year.
// Gist https://gist.github.com/440681ee258659c96d40eb9eb60b14e5
#include <iostream>
#include <string>
const int kThisYear{2022};
int main(int argc, char const *argv[]) {
int your_birth_year{0};
std::cout << "What year where you born? ";
std::cin >> your_birth_year;
int age{kThisYear - your_birth_year};
std::cout << "You were born in " << your_birth_year
<< " which means that you are " << age << " years old.\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment