1. ## Standard Deviation, etc.

The following functions should return the sum, average, and standard deviation of an array of integers. What's wrong with this code? (unfortunately I cannot test it myself right now). This is my first program in C, very exciting, hope you can help me. Thanks!

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char **argv)
{

int sum(int *numbers, unsigned short count){
int i;
int sum = 0;
for(i=0, i < count, i ++)
{   sum = sum + numbers[i];
}
return sum;
}

double average(int *numbers, unsigned short count){
float avg;
int sum;
sum = sum(numbers, count);
avg = sum/count;
return avg;
}

double sd(int *numbers, unsigned short count){
float avg;
int i;
float var;
int sum	= 0;

avg = average(numbers, count);
for(i = 0, i < count, i ++)
{	sum = sum + pow((numbers[i] - avg), 2);
}
var = sum/count;
return sqrt(var);
}

int numbers[] = {15, 0, -3, 7, 27743, 6, 8, 1, -5732, 1, 9};

printf("The sum is %d\n", sum(numbers, 11));
printf("The average is %7.2f\n", average(numbers, 11));
printf("The standard deviation is %7.2f\n", sd(numbers, 11));

return 0;
}
}```

Then, come back and edit your post to use code tags and proper formatting. You'll find us much more responsive that way. Thanks.

3. If you haven't run the program, how do you know there IS something wrong with it?

You test your own software -- and we'll test ours.

Come back if you have a problem with your program that you can't fix, OK?

No sense having a dozen people all testing a program that you can test, just as easily.

If you haven't run the program, how do you know there IS something wrong with it?

You test your own software -- and we'll test ours.

Come back if you have a problem with your program that you can't fix, OK?

No sense having a dozen people all testing a program that you can test, just as easily.
I would test it myself if I could! Unfortunately I can't, as I am without my own computer! I get what you're saying, but I assumed I made some visible mistakes, as this is my first program.

5. Yes, but many of those would be fixed by listening to compiler warnings. If you can't compile right now, not much point in it being fixed right now. When you get to your computer, fix all the compiler errors and warnings, then come back if you have actual problems with the logic/flow or don't understand the compiler messages. I will say, you need to stop being so messy with types. Use doubles only where you need decimal point data (they're different than floats) and ints where you only need whole numbers of something.

I would test it myself if I could! Unfortunately I can't, as I am without my own computer! I get what you're saying, but I assumed I made some visible mistakes, as this is my first program.
Beg borrow or steal some computer time....
You won't learn programming by writing phantom code then begging for help on the web.

8. Hint: 3/4 equals 0

Tim S.

9. Originally Posted by anduril462
I just know I'm stepping in it... but...
How is he here if he doesn't have a computer?
Why can't he compile it on the computer he's using?

10. Originally Posted by CommonTater
I just know I'm stepping in it... but...
How is he here if he doesn't have a computer?
Why can't he compile it on the computer he's using?
he could use an iPod touch like me to browse this forum. But writing code on it is a bit painful.

11. Originally Posted by CommonTater
I just know I'm stepping in it... but...
How is he here if he doesn't have a computer?
Why can't he compile it on the computer he's using?
Library!

Originally Posted by anduril462
Awesome.

Results:

Line 21: error: called object 'sum' is not a function
Why isn't sum a function?

12: for(i=0, i < count, i ++)

Line 12: error: expected ';' before ')' token
Line 12: error: expected expression before ')' token

what's wrong with for(i=0, i < count, i ++)

12. Originally Posted by stahta01
Hint: 3/4 equals 0
So do I need to make one of my ints into a float? any guidance here?

13. Don't put your functions inside main.

Line 21: error: called object 'sum' is not a function
Why isn't sum a function?
It is, but your local variable overrides the global symbol, so inside that function, sum is just a plain int. Rename it to total or some such.

12: for(i=0, i < count, i ++)

Line 12: error: expected ';' before ')' token
Line 12: error: expected expression before ')' token

what's wrong with for(i=0, i < count, i ++)
You need a semicolons not commas.