Thread: help with average

  1. #1
    Registered User
    Join Date
    Apr 2003

    help with average

    i don't know what i'm doing goal is to find tha average (mean) of number entered. but i keep getting the wrong answers.

    this is what o came up with so far..

    for (j=0;j<4;j++)
    printf("enter value:");
    scanf("%d", &i);
    total = 0;
    for (j=0;j<4;j++)
    total=total + i;
    average= total/4;
    printf("the average is %d", average);

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Stop posting new threads with the same topic.

    Why are you reading into i four times over and over? Every time you read into it, you change the value that was there.

    You've already been told: Use code tags or do not post at all.

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2003

    Thumbs down

    You have a big problem in the first for loop.
    int i is the integer used for the outer for loop but you are storing the number entered into that loop.
    Bad and BIG problem. you would be lucky if the loop goes for 4 times becuase if u enter 4, the loop terminates.

    Use an array or 4 different integers. You cant store 4 different numbers in one variable and hope to be able to use later on.
    One variable hold only one value at all time.

    Try yourself with array or four int and post the code when you got it or dont get it at all.

    *** Use some indents it is very hard to read and see the corresponding { } without indents. Use the code tag .

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Closed, answers over here please...
    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. Replies: 3
    Last Post: 02-22-2009, 02:54 PM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. Average score
    By wiz23 in forum C++ Programming
    Replies: 22
    Last Post: 05-05-2005, 05:38 AM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM