Thread: problem again :(

  1. #1
    Registered User
    Join Date
    Apr 2002

    problem again :(

    im having problems calculating the number of days until the 25/12/2002,

    here is my program (attached) so far, i know its messy but have a look and see wot i can do, thanks,


  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    What sort of problem? Do you have a specific problem with this, if not, I hate to say it, but there's plenty of example code here
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >Do you have a specific problem with this
    Yes, it doesn't work. Sadly, google doesn't help a great deal with the art of debugging code.

    >im having problems calculating the number of days until the 25/12/2002
    You're making this very hard on yourself, remember to keep programs and solutions as simple as possible or you'll get stuck on annoying details that cause trouble. This works.
    #include <stdio.h>
    struct dat{ 
       int day;   
       int month;
       int year;
    int main ( void )
      char loop ='y';
      while (loop == 'y'||loop == 'Y') {
        int leap, i, day = 0, total;
        struct dat t; 
        const int daytab[2] [13] = {
        printf("*A DATE CALCULATOR PROGRAM*\n");
        printf("Please enter a date from which you wish to calculate\n");
        printf("how many days until the 25/12/2002.\n\n"); 
        scanf("%d/%d/%d", &,&t.month,&t.year);
        leap = ( t.year % 4 == 0 && t.year % 100 != 0 || t.year % 400 == 0 );
        /* Rethink your error handling, it could be
        ** implemented better and more accurately.
        for (i = 1; i < t.month; i++)
          day += daytab[leap][i];
        day +=;
        if ( leap == 0 )
          total = 359 - day;
          total = 360 - day;
        printf("%d %s until 25/12/2002\n\n", total, (total == 1)?"day":"days");
        printf("Would you like to enter another date? (Y/N)\n");       
      return 0;
    However, it only works for the year 2002. You apparently haven't gotten to the part about handling multiple year spans, so I didn't do anything with it. Your input validation could also be improved by using a loop with simpler tests. I left that blank for you to fill in.

    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM