Hi! Thank you very much for the replies! I have not learned arrays yet, but I found out how to calculate stdev without arrays using a different stdev formula. I would appreciate if you could test it out and make sure everything is okay before I turn it in.
Disregard the ugly skeleton lol.
Code:
/***************************************************************************//* */
/* LEEWARD COMMUNITY COLLEGE */
/* PHYSICS AND ENGINEERING */
/* */
/* */
/* NAME: J. Preza */
/* */
/* DATE: 09/14/12 */
/* */
/* FILE: PROG2_STDEV_PREZA.C */
/* */
/* FUNCTION: To compute the standard deviation or sample standard */
/* deviation of a data set */
/* */
/* INPUTS: unit of data, data */
/* */
/* OUTPUTS: Mean(in proper unit) */
/* */
/***************************************************************************/
/*********************** PREPROCESSOR DIRECTIVES *************************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
/************************** MESSAGE FUNCTION *****************************/
void
msg1(void)
{
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" );
printf("\n EE 150 \n" );
printf("\n This program calculates the standard ");
printf("\n deviation of a given data set \n\n\n\n\n\n\n\n" );
}
/* SOMETIMES YOU WILL PUT OTHER FUNCTIONS HERE */
/*************************** MAIN FUNCTION *******************************/
int
main(void)
{
/********************* DECLARATION OF VARIABLES **************************/
double sum = 0, calculation = 0, data, square, stdev;
int n = 0;
char unit[20], ans='Y';
/*******************THE EXECUTABLE PART OF THE PROGRAM ********************/
msg1();
printf("\n\nPlease enter the unit of the data set: >");
scanf("%s", &unit);
while (ans=='y'||ans=='Y')
{
printf("\n\nEnter the data point (in %s): >", unit);
scanf("%lf", &data);
n = ++n;
calculation += data*data;
sum+=data;
printf("\n\nDo you want to add another data point? Y for yes. N for no.\n");
scanf("%c", &ans);
scanf("%c", &ans);
}
if (ans=='n'||ans=='N')
{
square = sum * sum;
stdev = sqrt(((n*calculation)-square)/(n*(n-1)));
printf("\n\nThe Standard Deviation of the data set in %s is %g.", unit,stdev);
}
return 0;
}
/***************************************************************************/
Thanks!!!!!!!!!!!!!!!