code won't compile, can't see the error, help troubleshooting

This is a discussion on code won't compile, can't see the error, help troubleshooting within the C Programming forums, part of the General Programming Boards category; My compiler tells me I have an error in line 100 with an output error in daysinmonth. This doesn't make ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    22

    code won't compile, can't see the error, help troubleshooting

    My compiler tells me I have an error in line 100 with an output error in daysinmonth. This doesn't make sense to me as I wasn't messing with that function at the time it came out as an error. heres the code, is there something I'm missing? At first it told me the variable i was not initialized, so I made the variable global and that gave me this new error...
    Code:
    #include <stdio.h>
    #include <time.h>
    int days, month, year, days_1, month_1, year_1, leapy=0, ndays, ddays, days_total=0, days_beforeleap, days_years, i;
    
    int daysinmonth(int month)
    {
            switch(month)
            {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                    return 31;
            case 2:
                    return 28;
            case 4:
            case 6:
            case 9:
            case 11:
                    return 30;
            default:
                    return -1;
            }
    int is_leap_year(int year)
    {
            while(year<year_1)
            {
                    if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
                    {
                    ++leapy;
                    ++year;
                    }
                    else
                    {
    
                    ++year;
                    }
            }
    
    }
    int daystoyears(int year,int year_1)
    {
    int total_years;
    total_years=year_1-year;
    days_years=total_years*365;
    return days_years;
    }
    int daysinyear(int days, int month, int days_1, int month_1)
    {
    int i;
    for(i = month;i < month_1;++i)
    days_total += daysinmonth(i);
    
    days_total+=days_1;
    days_total=days_total-1;
    return days_total;
    }
    
    int main(void)
    {
    char a, b, a1, b1;
    printf("intput a date in the follwing format:\n");
    printf("mmddyyyy: in other words the two digit day,two digit month,\n");
    printf("and four digit year, with no slashes or heifens anywhere.\n");
    scanf("%d%c%d%c%d", &month, &a, &days, &b, &year);
    printf("enter the later date in the same format:\n");
    scanf("%d%c%d%c%d", &month_1, &a1, &days_1, &b1, &year_1);
            if(month<0 || month>12 || days<0 || days>31 || year<0)
            {
            printf("data not valid\n");
            exit(1);
            }
    
            if(year>year_1)
            {
            printf("data not valid\n");
            exit(1);
            }
            if(year==year_1 && month>month_1)
            {
            printf("data not valid\n");
            exit(1);
            }
            if(year==year_1 && month==month_1 && days>days_1)
            {
            printf("data not valid\n");
            exit(1);
            }
    daysinyear(days, month, days_1, month_1);
    printf("total days=%d\n",days_total);
    daystoyears(year, year_1);
    printf("total days=%d\n",days_years);
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    22
    nevermind, I'm an idiot, disregard that.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    ^^^^ ROFL! ^^^^

    We've all been there!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. troubleshooting beginning array code
    By killerwhalepat in forum C Programming
    Replies: 2
    Last Post: 06-24-2011, 08:22 AM
  2. Troubleshooting code
    By bcianfrocca in forum C++ Programming
    Replies: 11
    Last Post: 11-17-2005, 05:46 PM
  3. prime numbers code compile error
    By Tony654321 in forum C Programming
    Replies: 5
    Last Post: 10-10-2004, 11:13 AM
  4. compile error in this code
    By blue_gene in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2004, 08:55 AM
  5. ....this code doesn't compile, very odd error
    By Leeman_s in forum Windows Programming
    Replies: 2
    Last Post: 11-03-2002, 02:31 PM

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