Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6848237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:50:36+00:00 2026-05-27T00:50:36+00:00

I am trying to create a program that finds out how many months they

  • 0

I am trying to create a program that finds out how many months they have been alive, but have been running into some issues. Here is my function so far:

int getResult(int year, month, day, endResult)
{
    int thisYear, thisMonth, thisDay;

    year = thisYear - year;

    year *= 12;
}

And what I’m trying to accomplish would show an output like:

Output: 
What year were you born? 
1989 
What month were you born? 
5 
What day were you born? 
23 
You are x months old.

I was going to continue with months but then I realized, what if the month they were born is in after this month or before? So, if anyone has any tips on how to calculate that, I’d appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:50:37+00:00Added an answer on May 27, 2026 at 12:50 am

    Let’s see. First, let’s say now is:

    year_now and month_now
    

    and your birthday is:

    year_birth and month_birth
    

    Now, we go case by case:

    • month_now == month_birth: as you have already computed:

      months_old = (year_now-year_birth)*12
      
    • month_now > month_birth: easily, you have:

      months_old = (year_now-year_birth)*12 + (month_now-month_birth)
      
    • month_now < month_birth: in this case, (year_now-year_birth)*12 gives you more months then necessary, and you have to subtract:

      months_old = (year_now-year_birth)*12 - (month_birth-month_now)
      

    Now if you look carefully, you will see that they are all in fact the same formula:

    months_old = (year_now-year_birth)*12 + (month_now-month_birth)
    

    (in the third case, month_now-month_birth is negative)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a Ruby program that will be running online
I am trying to create a program that will do some simple calculations, but
I have been trying to create a simple program with Python which uses OpenCV
I am trying to figure out how to create a java program that can
I'm trying to create a program that takes a text file of c++ code
I'm currently trying to create a program that estimates location based on signal strength.
Alright so what I am trying to do is essentially create a program that,
My program is trying to create an key on the HKLM\Software\Microsoft\Shared Tools\MSCONFIG\startupreg\test\ but instead
I'm trying to create a program that reads in a .txt file with multiple
I'm trying to create a program that reads a .docx file and posts it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.