Thread: average of total using array

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    17

    average of total using array

    i have to find the average for this program...
    i've tried average = total/i; but it still doesn't work...thanks

    #include<stdio.h>
    int main()
    {
    int i, grade[14],total=0, average;

    for (i=0; i<14; ++i)
    {
    printf("enter grade:");
    scanf("%d", &grade[i]);
    }
    printf("\nthe total grade entered is");
    for(i=0; i<14; ++i)
    {
    printf("%d", grade[i]);
    total += grade[i];
    average = total/i;

    }
    printf("is %d ", total);
    printf("the average grade is %d", average);
    return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    average = total/i;
    You only need your average once. When your total loop is finished, then do the average.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Please use code tags when posting code.
    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. What's wrong with my Average Array program?
    By special1zed in forum C Programming
    Replies: 12
    Last Post: 03-15-2009, 11:01 PM
  2. average of an array
    By mrsirpoopsalot in forum C Programming
    Replies: 20
    Last Post: 09-16-2006, 04:32 PM
  3. Need Help With Array Function
    By RP319 in forum C++ Programming
    Replies: 10
    Last Post: 04-12-2005, 07:37 AM
  4. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  5. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM