Thread: warning #2229?

  1. #1
    Registered User Eddie Ramos's Avatar
    Join Date
    Jan 2012

    warning #2229?

    #include <stdio.h>
    int main(void)
        int count_emp = 0;
        int numb_days = 0;
        double temp;
        double total_temp;
        int average_temp;
        printf ("Please enter number of days (1-7):\n");
        scanf ("%d" ,&numb_days);
        while (count_emp < numb_days)
        printf ("Please enter the temperature:\n");
        scanf ("%lf" ,&temp);
        total_temp = total_temp + temp;
        count_emp = count_emp +1;
        average_temp = total_temp / numb_days;
        printf ("All temperatures have been entered\n");
        printf ("Average temperature of %d\n" ,average_temp);
    I get a warning message:
    warning #2229: Local 'total_temp' is potentially used without being initialized.

    I run the program and seems to do what its suppose to. can someone please explain why i'm getting this warning?

  2. #2
    Registered User
    Join Date
    May 2011
    Around 8.3 light-minutes from the Sun
    You are getting the warning because you declared total_temp, however failed to initialize it to a value. Theoretically, it could start out at any value. Only global variables are guaranteed to be initialized to 0 per the standard.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > double total_temp;
    > total_temp = total_temp + temp;
    What is the original value here?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-12-2011, 06:59 PM
  2. Replies: 9
    Last Post: 05-28-2010, 10:11 AM
  3. warning
    By pe4enka in forum C Programming
    Replies: 2
    Last Post: 05-03-2010, 08:35 AM
  4. how do I get rid of this warning?
    By -EquinoX- in forum C Programming
    Replies: 6
    Last Post: 11-06-2008, 12:11 PM
  5. Warning
    By RobR in forum C++ Programming
    Replies: 0
    Last Post: 03-22-2002, 03:44 PM