Solved

# average for numbers inputed

Posted on 2011-02-25
313 Views
The average kept coming out wrong.
float total = 0;
for(i = 0; i < 9; i++) {
total += array[i ];
}

float average = total/9;

why does the average not add up right, im using the basic numbers 1, 2,3, 4, 5, ,6 ,7, 8, 9 so i know the correct average.
0
Question by:HelpMeMaggi
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 24

Expert Comment

ID: 34986162
You should write it as follows:

float total = 0;
for(i = 0; i <= 9; i++) {
total += array[i ];
}

0

LVL 24

Expert Comment

ID: 34986166
Sorry that was incorrect, it should be:

float total = 0;
for(i = 0; i < 9; i++) {
total += array[i ];
}

0

Author Comment

ID: 34986173
I have, the average comes out wrong still.
0

LVL 84

Accepted Solution

ozo earned 500 total points
ID: 34986186
>  im using the basic numbers 1, 2,3, 4, 5, ,6 ,7, 8, 9
the ,, between the 5 and 6 would be a syntax error
float average = total/9.0;
or
will do a floating  division rather than an integer division
0

LVL 24

Expert Comment

ID: 34986219
What is the result that you get?
0

Author Comment

ID: 34986227
That worked, Thank you!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address.Ā This address might be address of another variable/address of devices/address of fuā¦
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to useā¦
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
###### Suggested Courses
Course of the Month3 days, 5 hours left to enroll