Thread: what is wrong with my code, my program stops

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    2

    what is wrong with my code, my program stops

    Code:
    #include<stdio.h>
    
    
    int main ()
    {
                int size,temperature[size];
                int i,A,sizeOfDays,average=0,hotDay=0,coldDay=0,pleasantDay=0;
    
    
                    printf("\n\tHow many days to record \n\n\t\t");
                    scanf("%d",&size);
    
    
            printf("\n\n Please Enter %d days Temperature readings \n\n ",size);
    
    
                for(i=0;i<size;i++)
    
    
                    {
    
    
                        printf("\t Temperature day [%d] => ",i+1);
                        scanf("%d",&temperature[i]);
    
    
                        if (temperature[i]>=85)
                    {
    
    
                            hotDay++;
                            printf("\n\t Celsius very Hot \n\n\n");
                    }
    
    
                         else if (temperature[i]>=60&&temperature[i]<=84)
                    {
    
    
                            pleasantDay++;
                            printf("\n\t Celsius Pleasant Day \n\n\n");
    
    
                    }
                        else if (temperature[i]<60)
    
    
                    {
    
    
                            coldDay++;
                            printf("\n\t Celsius Very Cold \n\n\n");
                    }
    
    
    
    
                    average += temperature[i] / size ;
    
    
    
    
                for(A=0;A<size;A++)  /* I'm including this extra looping, which  somehow helps me the program to run and work as long as the size entry is less than 10 . if exceeds,the program stops, and also if this looping is removed*/ 
                {
                  //  printf("print nothing");  
                }
    
    
                    }
                        printf("Number of Hot Day/s is %d \n\n",hotDay);
                        printf("Number of Pleasant Day/s is %d \n\n",pleasantDay);
                        printf("Number of Cold Days is %d \n\n",coldDay);
                        printf("The average Temperature for %d Days is %d \n\n\n",size,average);
    
    
    
    
        return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > int size,temperature[size];
    Your size is uninitialised when you get to declare the array.

    > scanf("%d",&size);
    Your array already exists - you're too late.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    2
    well .... that helped me ... Salem, thank you so much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ATM Program, what's wrong with my code?
    By kimimaro619 in forum C Programming
    Replies: 3
    Last Post: 03-19-2015, 12:12 PM
  2. What's wrong with the code(Calculator program)
    By rizwan in forum C Programming
    Replies: 10
    Last Post: 10-19-2011, 05:59 PM
  3. Replies: 8
    Last Post: 03-29-2010, 04:38 AM
  4. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  5. Stops before the end of the code.
    By Elivmar in forum C++ Programming
    Replies: 14
    Last Post: 10-08-2005, 01:56 PM