Ok been working on it some more... I can't seem to get the biggest value to print.... Its in different font
Code:
/* Melissa Schwager Homework 4
Write a program that will accept the number of points
and then read in the points that are to be stored in an array.
The program will then call functions that
a) find the average of the values in the array
b) find the largest value in the array
c) find the smallest value in the array
d) find the variance of the values */
/* starter code below */
#include <stdio.h>
#include <stdlib.h>
/*a)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
double findAve(int numberPts, double vals[])
{
double sum = 0;
int i;
for (i = 0; i < numberPts; i++)
sum = sum + vals[i];
return sum/numberPts;
}
/*b)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
double findBiggest(int numberPts, double vals[])
{
double sum, biggest = 0;
int i;
for (i = 0; i < numberPts; i++)
sum = sum = vals[i];
return sum/numberPts;
}
/*c)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
double findSmallest(int numberPts, double vals[])
{
double smallest = 0;
int i;
double sum;
for (i = 0; i < numberPts; i++)
sum = sum + vals[i]; /* Need code similar to findBiggest */
return i,smallest,numberPts;
}
/*d)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
double CalcVariance(int numberPts, double vals[])
{
double sumsq=0, mean, variance; /*move these later */
int numpts, i; /* mean = findAve..... ****/
for (i = 0; i < numpts; i++) /* move to CalcVariance*/
{
double diff = vals[i] - mean;
sumsq = sumsq + (diff * diff);
}
variance = sumsq/(numpts - 1);
printf("Variance = %lf", variance);
return 0.0;
}
int main()
{
double values[20];
int numpts, i;
double mean;
double biggest = -1000000; /*really negative */
printf("Enter the number of points: ");
scanf("%d", &numpts);
if (numpts <= 1)
{
printf("At least 2 points must be entered\n");
return 0;
}
for (i = 0; i < numpts; i++)
{
printf("Enter a value: ");
scanf("%lf", &values[i]);
}
mean = findAve(numpts, values);
printf("Average = %lf\n", mean);
biggest = findBiggest(numpts, values);
printf("Biggest = %lf\n", biggest);
return 0;
}
Only thing that does work is the advage trying to break it down in parts and get each part working till I move to the next, I"m hoping that if I get the bigest to work I can figure out the rest from that... however I have no clue about the valnce.
this is one example of me runing the program using 2 and 4...
Code:
Enter the number of points: 2
Enter a value: 2
Enter a value: 4
Average = 3.000000
Biggest = 2.000000
>Exit code: 0
thanks for any help