i need help for my school project in it. the function of the program is like a calculator that computes mean, median, mode, range, percentile, & standard deviation. and i dont know how to compute for mode, standard deviation and percentile. please they gave us dev c++ for out it subject in our senior year in highschool.

#include<stdio.h>
#include <math.h>

int main()
{
      int Menu, Data, Choice, Counter=1, Num, Limit, Num1, Mean_Sum=0, Range, Max=0, Min=1, i;
      float Mean, Median, Value, First_Value, Second_Value, mode, SD[100];
      system("color f5");
        printf("\t\t\t-------------------------------\n\n\n");
      printf("\t\t   H E A L T H  F I T N E S S  C O M P A N Y\n\n\n");
      printf("\t\t\t-------------------------------\n\n\n");
      printf("\t\t\tBY  CHAN,  DEMOLAR,  DOMINGO,  PINOL\n\n\n");
      printf(" Describing datas of Hand Span, Wrist Circumference and Neck Circumference\n\n\n");
      printf("\t\t\t\t4 - St. Francis Borgia\n\n\n\n");
      printf("\t\t\t\tPress [1] for Start\n\n\t\t\t\t\t");
      scanf("%d", &Menu);


      while(Menu==1)
      {
      system("cls");
        printf("DATA\n\n");
                   printf("Hand Span [1]\n\n\n");
                   printf("Wrist Circumference[2]\n\n\n");
                   printf("Neck Circumference[3]\n\n\n");
                   printf("Press [0] to go back.");
                   scanf("%d", &Data);


       do 
     { 
      if(Data==1||Data==2||Data==3)
      {
                system("cls");
                printf("What do you want to know?\n\n");
                printf("Range[1]\n\n");
                printf("Mean[2]\n\n");
                printf("Median[3]\n\n");
                printf("Mode[4]\n\n");
                printf("Standard Deviation[5]\n\n");
                printf("Percentiles[6]\n\n");
                scanf("%d", &Choice);
    }

                 if(Choice==1)
                 {
                            system("cls");
                            printf("Range - difference between the largest and smallest values\n");
                            printf("Range = MAXIMUM - MINIMUM\n\n");
                             printf("How many students?");
                            scanf("%d", &Num);

                   for(Counter=1;Counter<=Num;Counter++)
                            {
                                      printf("Enter Value %d: ", Counter);
                                      scanf("%d", &Num1);

                                       if(Counter==1)
                                      {
                                           Min=Num1; 
                                           Max=Num1;
                                      }

                                      else if(Num1>=Max)
                                      {
                                           Max = Num1;
                                      }
                                      else if(Num1<=Min)
                                      {
                                           Min = Num1;
                                      }

                            }
                            Range=Max-Min;

                            printf("\nRange of the data is %d" , Range);

                            printf("\nBack to Menu[1]");
                            scanf("%d",&Data);


                 }
                 else if(Choice==2)  
                 {          

                            system("cls");    
                            printf("Mean - the sum of a collection of numbers divided by the number of numbers in the collection\n");
                            printf("\nHow many students?");
                            scanf("%d",&Limit);

                            while (Counter<=Limit)
                  {
                    printf("Enter data #%d:", Counter);
                    scanf("%d", &Num1);

                    Mean_Sum = Mean_Sum + Num1;
                    Counter++;
                }
                    Mean = Mean_Sum/Limit;
                    printf("The mean is: %.2f", Mean);
                    getch();

                            printf("\n\nBack to Menu[1]   ");
                            scanf("%d",&Data);

                 }

                  else if(Choice==3) 
                 {          
                            system("cls");    
                           printf("Median - the numerical value separating the higher half of a data sample, a population, or a probability distribution, from the lower half.\n");
                            printf("\nHow many students?");
                            scanf("%d",&Num);
                            printf("Note: Remember to input the data from least to greatest.");

                             Counter=1;
                            while(Counter<=Num)
                            {
                                           if(Num%2!=0)
                                           {
                                                  Value=(Num+1)/2;
                                                  printf("\n\nEnter Value %d:  ", Counter);
                                                  scanf("%d", &Num1);
                                                  if(Counter == Value);
                                                       Median=Num1;
                                                  Counter++;
                                           }
                                           else if (Num%2==0)
                                           {
                                                Value=(Num+1)/2;
                                                printf("\n\nEnter Value %d:  ", Counter);
                                                scanf("%d", &Num1);

                                                if(Counter==Value-0.5)
                                                {
                                                         First_Value=Num1;
                                                }
                                                else if (Counter==Value+0.5)
                                                {
                                                         Second_Value=Num1;
                                                }
                                                Median=(Second_Value+First_Value)/2;
                                           }             
                            }

                                   printf("The median of the data is %.2f", Median );
                                   getch();

                            printf("\n");
                            printf("Back to Menu[1]   ");
                            scanf("%d",&Data);

                 }          
                  else if(Choice==4) 
                 {          
                            system("cls");    
                             printf("Mode - the value that appears most often in a set of data.\n");
                            printf("\nHow many students?");
                            scanf("%d",&Num);

                            printf("Back to Menu[1]");
                            scanf("%d",&Data);


                 }          
                  else if(Choice==5)
                 {          
                            system("cls");    
                            printf("\n");
                            printf("\t\t\t\t STANDARD DEVIATION");
                            printf("\n");
                            printf("How many numbers?");
                            scanf("%d", &Num);

                        do
                            {
                                      printf("Enter Value %d:  ", Counter);
                                      scanf("%d", &Num1);

                                      Mean_Sum=Mean_Sum+Num1;
                                      Mean=Mean_Sum/Num; 
                                      Counter++;  

                            }

                         while (Counter<=Num);




                            printf("Back to Menu[1]");
                            scanf("%d",&Data);        
                 }
                 else if(Choice==6) 
                 {          
                            system("cls");    
                            printf("\n");
                            printf("\t\t\t\t PERCENTILES");
                            printf("\n");
                            printf("\n");
                            printf("\t\tMean is the average of all the data.");
                            printf("\n");
                            printf("\t\t\tmax=maximum value");
                            printf("\n");
                            printf("\t\t\tmin=minimum value");
                            printf("\n");
                            printf("\t\t\tRange= max-min");
                            printf("\n");
                            printf("\n");
                            printf("Back to Menu[1]");
                            scanf("%d",&Data);



                 }          



                else 
                {
                     system("cls");
                     printf("\n\t\t\tPlease Enter 1 to Go Main Menu:");
                     scanf("%d", &Data);
                }

                printf("Back to Menu:");
                scanf("&d", &Data); 
      }    
      while(Data==0);
                printf("Back to Menu:");
                scanf("&d", &Data);    
      }

      getch();
}

Edited 2 Years Ago by gesha

The mode average is the value that comes up most frequently. Get all the values, look at each one in turn, and count up how many of each there are.

Edited 2 Years Ago by Moschops

Where do you input your data?
Do they come from a file? a database? Manual input?
btw It doesn't make much sense to calculate percentiles if your data size is less than 20 samples.

Edited 2 Years Ago by ddanbe: typo

Your program logic flow could be simplified by using several functions ... one function to do each 'job'.

Then you can simply call those functions in sequence.

A common way to get your data is to read it from a file.

Suppose the file held the height (inches) and weight (pounds) of a large number of people for you to process,

Suppose also that the file data was structured as follows:

// file name: HeightWeight.txt
60.5 205.5
56.25 153.5
// ... etc

Now, you could read all this data into an array ...
(with the max array size pre-fixed, at compile time, to be large-enough) ..

i.e. an array of C struct

using something like this:

typedef struct
{
   float height;
   float weight; 

} HeightWeight;

int fillFromFile( const char fname[], HeightWeight ary[], unsigned max_ary_size )
{
   FILE* fin = fopen( fname, "r" );
   int size = 0;
   if( fin )
   {
      while( size < max_ary_size && fscanf( fin, "%f %f", &ary[size].height, &ary[size].weight ) == 2 ) ++ size;

     fclose( fin );
     return size;
   }
   else return -1; /* to 'flag' file open error */
}

Now in main, you would do something like this:

int size = fillFromFile( "HeightWeight.txt", ary, 100 );
if( size )
{
   /* process the array of data  */
}
else printf( "No data read ... check file name ok\n" );

Edited 2 Years Ago by David W

Your program logic flow could be made clearer by using individual functions for each 'job' ...

A common way to get your data is to read it from a file.

Suppose the file held the height (inches) and weight (pounds) of a large number of people for you to process.

Suppose also that the file data was structured as follows:

// file name: HeightWeight.txt
60.5 205.5
56.25 153.5
// ... etc

Now, you could read all this data into an array ...
(with the max array size pre-fixed, at compile time, to be large-enough) ..

i.e. an array of C struct

using something like this:

typedef struct
{
   float height;
   float weight; 

} HeightWeight;

int fillFromFile( const char fname[], HeightWeight ary[], int max_ary_size )
{
   FILE* fin = fopen( fname, "r" );
   int size = 0;
   if( fin )
   {
      while( size < max_ary_size && fscanf( fin, "%f %f", &ary[size].height, &ary[size].weight ) == 2 ) ++ size;

     fclose( fin );
     return size;
   }
   else return -1; /* to 'flag' file open error */
}

Now in main, you would do something like this:

HeightWeight ary[100]; /* get space for 100 records */
int size = fillFromFile( "HeightWeight.txt", ary, 100 );
if( size != -1 )
{
   /* process the array of data  */
}
else printf( "No data read ... check file name ok\n" );

As you process your data, you could call (a) function(s) that find and return the values you seek. perhaps returning a struct that holds all those calculated values ...

typedef struct
{
   float min;
   float max;
   float mean;
   float mode;
   float stdDev;

} MyStats ;

If you return a struct like this, after all processing done, then you can easily report the 'stats' ...

Edited 2 Years Ago by David W

Or ...you could return a struct like this, after all processing done, to easily report the 'stats' for BOTH of height and weight ...

(You could store weight stat's using index 0, and height stat's using index 1)

typedef struct
{
   float min[2];
   float max[2];
   float mean[2];
   float mode[2];
   float stdDev[2];

} MyStats ;
This article has been dead for over six months. Start a new discussion instead.