so this is my code so far sorry its quite messy, and yeah had a look at the wiki and and rosetta code had a play around with what they suggest but cant get it to work. as you can see for "option 2" i have i have worked out the average from the integers stored in the array but im at a loss for the RMS
cheers max
Code:
#include <stdio.h>
#include <math.h>
main(){
int sum = 0;
int count = 0;
int in;
int i;
int j = 0;
int array[10000];
FILE *instream;
int avg;
instream = fopen ("data1.txt", "r");
char str[1000];
int input;
while ( !feof(instream) )
{
fscanf(instream,"%d",&in);
array[count] = in;
count++;
}
while (input !=5)
{
printf ("please select an option\n\r" "Enter 1 to print out all values\n" "Enter 2 to calculate the mean value\n" "Enter 3 to calculate the RMS\n" "option 4\n" "option 5\n\n");
fgets(str,1000,stdin);
sscanf(str, "%d", &input);
if (input ==1)
{
printf ("you have entered 1\n");
for ( i = 0 ; i < count ; i++ )
{
printf("%d\n",array[i]);
}
}
else if (input ==2)
{
printf ("you have entered 2\n");
for ( i = 0 ; i < count ; i++ )
sum = sum + array[i];
{
avg = sum/count;
printf("%d\n^ your average\n",avg);
}
}
else if (input ==3)
{
printf ("you have entered 3\n");
}
else if (input ==4)
{
printf ("you have entered 4\n");
}
else if (input ==5)
{
printf ("you have entered 5, the program will now close\n");
}
}
getchar ();
}