C++ help!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gwenky
    New Member
    • Feb 2008
    • 10

    C++ help!!

    Hello, I'm new to C++. A few years ago I took a C programming course, so I feel shaky with both. Today my question is related to an age in days and age in months program I'm writing. I can get the total year and months, but I'm having a hard time figuring out how to find the days. In this particular case I do not have to worry about leap year. And, Feb always =28.

    This is the bit I have for months that works:

    total_yr = today_yr - dob_yr;
    total_mo = total_yr * 12;

    if (dob_mo > today_mo)
    {
    new_dob_mo = dob_mo - today_mo;
    total_mo_count = total_mo - new_dob_mo;
    }

    but my extension of this for days is not complete and I cannot see how to figure out the days part....

    if (dob_mo > month)
    {
    total_yr = (year - dob_yr);
    extra = dob_mo - month;
    total_mo = (total_yr * 12) - extra;
    if (day != dob_day) && (day < dob_day)
    {
    total_day = today;
    }
    if (day != dob_day) && (day > dob_day)
    total_day =
    }
    else
    {
    extra = month - dob_mo;
    total_yr = (year - dob_yr);
    total_mo = (total_yr * 12) + extra;
    total_day =
    }

    Any help in what to look for would be greatly appriciated!
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by gwenky
    Hello, I'm new to C++. A few years ago I took a C programming course, so I feel shaky with both. Today my question is related to an age in days and age in months program I'm writing. I can get the total year and months, but I'm having a hard time figuring out how to find the days. In this particular case I do not have to worry about leap year. And, Feb always =28.

    This is the bit I have for months that works:

    total_yr = today_yr - dob_yr;
    total_mo = total_yr * 12;

    if (dob_mo > today_mo)
    {
    new_dob_mo = dob_mo - today_mo;
    total_mo_count = total_mo - new_dob_mo;
    }

    but my extension of this for days is not complete and I cannot see how to figure out the days part....

    if (dob_mo > month)
    {
    total_yr = (year - dob_yr);
    extra = dob_mo - month;
    total_mo = (total_yr * 12) - extra;
    if (day != dob_day) && (day < dob_day)
    {
    total_day = today;
    }
    if (day != dob_day) && (day > dob_day)
    total_day =
    }
    else
    {
    extra = month - dob_mo;
    total_yr = (year - dob_yr);
    total_mo = (total_yr * 12) + extra;
    total_day =
    }

    Any help in what to look for would be greatly appriciated!

    You miss a bracket in the line here
    [code=c]
    if( (day != dob_day) && (day < dob_day))
    {
    total_day = today;
    }
    if( (day != dob_day) && (day > dob_day))

    [/code]
    Try changing it and run again.
    I havent checked the logic yet.

    Raghuram

    Comment

    • gwenky
      New Member
      • Feb 2008
      • 10

      #3
      Originally posted by gpraghuram
      You miss a bracket in the line here
      [code=c]
      if( (day != dob_day) && (day < dob_day))
      {
      total_day = today;
      }
      if( (day != dob_day) && (day > dob_day))

      [/code]
      Try changing it and run again.
      I havent checked the logic yet.

      Raghuram

      Thanks, I did notice that ...I am not looking for the "answer" but rather why my logic is off? I closed the bracket and added the ; but the issue remains that I know I'm not accounting for the days correctly. Any suggestions on articles to read? Or....??

      Comment

      Working...