1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

how many days has it been this year?

Discussion in 'Software Development' started by 2xaron, Nov 11, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. 2xaron

    2xaron Thread Starter

    Joined:
    Nov 10, 2006
    Messages:
    5
    I am trying to make a program where the user inputs a date, and the output will be how many days have passed so far in ther year. using c++ this program does not work! just my ideas so far
    __________________________________________________________________________

    cin >> day , month , year;
    for (q = 0; q < month; ++i){
    int q;
    cin >> q;
    switch (q){
    case 1: case 3: case 5: case 7: case 8: case 10: case 12:
    monthdays = 31;
    break;
    case 2:
    monthdays = 28;
    break;
    case 4: case 6: case 9: case 11:
    monthdays = 30;
    break;
    }
    totaldays = (monthdays + monthdays);
    cout << totaldays;
    }
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
  3. 2xaron

    2xaron Thread Starter

    Joined:
    Nov 10, 2006
    Messages:
    5
    ya but i need the logic to the thing ne ideas to build upon what i already have?
     
  4. dquigley

    dquigley

    Joined:
    Apr 17, 2006
    Messages:
    112
  5. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    I am not going to completely write the code for you. You need to use Julian dates.
     
  6. AGCurry

    AGCurry

    Joined:
    Jun 15, 2005
    Messages:
    431
    In the Unix world, I would use the library functions for date and time. Squashman has given you a couple of good links.

    Maybe you're taking a class and aren't supposed to know about those yet. If so, it looks like your switch statement is pretty much okay, but you DO need to figure out how to sum the desired result. It looks like you need some sort of iteration.
     
  7. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Good advice about Julian calanders and iteration.

    Dates, as we know them today, are specified, for example, in terms of month, day, year or day, month, year or year, month, day or year, day or day, year. Then again, the number of days in a year can vary from 365 to 366 depending on whether it is a leap year. Knowing the day of the year requires mapping to a calendar date or visa versa, and requires a way to transform between the two.

    If you needed to know the the day of the week, there are only 14 calendars: one map where Jan 1st occurs on each day of the week for a non-leap year, and another map where Jan 1st occurs on each day of the week for a leap year - but that is not within the requirements of solving your problem.

    In your message, you did not account for a 29 day February for a leap year.

    Good luck,

    -- Tom
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/517543