wots going on?

This is a discussion on wots going on? within the C Programming forums, part of the General Programming Boards category; can anyone explain why this isnt working? The printf that ive hidden from the compiler seems to cock it up?? ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    32

    wots going on?

    can anyone explain why this isnt working? The printf that ive hidden from the compiler seems to cock it up??

    CODE:

    #include <stdio.h>
    #include <clib.h>



    struct dat{

    int day;
    int month;
    int year;
    };


    main()
    {

    char loop ='y';
    while (loop == 'y'||loop == 'Y')




    {
    int leap, *mt, *yr, *ly, i,day, day1, year1, month1, leap_yr, year2, month2, total;


    struct dat t;

    static char daytab[2] [13] = {
    {0,31,28,31,30,31,30,31,31,30,31,30,31},
    {0,31,29,31,30,31,30,31,31,30,31,30,31}
    };
    system ("cls");
    printf("***************************\n");
    printf("*A DATE CALCULATOR PROGRAM*\n");
    printf("***************************\n\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.day,&t.month,&t.year);
    leap = ( t.year % 4 == 0 && t.year / 100 != 0 || t.year % 400 == 0 );
    if (t.day <= 0)

    printf("ERROR, there are no months with that number of days!\n");

    else if (t.month > 12 ||
    t.month <= 0)

    printf("ERROR, there are no years with that many months!\n");

    else if ((t.month == 1||
    t.month == 3||
    t.month == 5||
    t.month == 7||
    t.month == 8||
    t.month == 10||
    t.month == 12) && t.day > 31)

    printf("ERROR, the month you have entered doesnt have that many days in it!\n");

    else if ((t.month == 4||
    t.month == 6||
    t.month == 9||
    t.month == 11) && t.day > 30)

    printf("ERROR, the month you have entered doesnt have that many days in it!\n");

    else if (t.month == 2 && t.day == 29 && leap == 0)

    printf("ERROR, the year you've entered isn't a leap year!\n");

    else if (t.month == 2 && t.day > 29 && leap != 0)

    printf("ERROR, although this is a leap year, there arnt that many days in February!\n");
    {
    if (t.month == 1)
    month2 = 31;
    else if( t.month == 2)
    month2 = 28;
    else if( t.month == 3)
    month2 = 31;
    else if( t.month == 4)
    month2 = 30;
    else if( t.month == 5)
    month2 = 31;
    else if( t.month == 6)
    month2 = 30;
    else if( t.month == 7)
    month2 = 31;
    else if( t.month == 8)
    month2 = 31;
    else if( t.month == 9)
    month2 = 30;
    else if( t.month == 10)
    month2 = 31;
    else if( t.month == 11)
    month2 = 30;
    else if( t.month == 12)
    month2 = 31;

    }
    {

    year2=(2002-t.year)*365;


    if(leap == 0)
    leap_yr=1;
    else
    leap_yr=0;

    total = t.day+month2+year2+leap_yr;



    // printf("There are %d days until the 25/12/2002\n\n" total);

    }


    printf("Would you like to enter another date? (Y/N)\n");
    scanf("\n%c",&loop);
    }
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: wots going on?

    Originally posted by brad123
    The printf that ive hidden from the compiler seems to cock it up??
    If it's in the source file, it's not hidden from the compiler

    If you're talking about commenting stuff out, some compilers will only accept /* comments */ as opposed to // comments

    Can you re-phrase ya question?

    Also, isn't this part of the other thread you started? If so, please try and limit yourself to one only

    PS Use the code tags please!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    32
    sorry about not using tags, the program works if i hide the printf line, but obviously wont display the answer because that line is needed for that. im just wondering why it isnt working

    Brad.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    // printf("There are %d days until the 25/12/2002\n\n" total);
    you mean this one? It has a comma missing from it, is that ya problem?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wots this mean?
    By Fountain in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 08-31-2002, 07:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21