Menu Display Help

This is a discussion on Menu Display Help within the C Programming forums, part of the General Programming Boards category; ASsignment::Write a menu-driven mini-statistics package. A user should be able to enter up to 200 items of float data. The ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    17

    Menu Display Help

    ASsignment::Write a menu-driven mini-statistics package. A user should be able to enter up to 200 items of float data. The program should calculate the number of items in the data, the mean, the standard deviation, the variance, the median, and the mode of the data. A sample run follows. The symbol <EOF> in the sample run below should be replaced with CTRL-Z or CTRL-D

    I have no problems with the actual display but the output of the variables.
    I can't seem to get any of the variables to come out correct as they always have 0.00 or "#J"




    Code:
    #include  <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    void readData(float[],int count);
    float mean(float[],int);
    float sd(float[],int);
    float min(float[],int);
    float max(float[],int);
    float median(float[],int);
    
    main()
    {
                
     float data[200];
    int choice,count=0,i;
                
    do
    {
      printf("\nThis program will perform the following:");
       printf("\n1.Enter Data\n2.Display the data and the following statistics:\n");
        printf("the number of date item, the high and low values in the data, \n the mean, median, mode, variance and standard deviation.");
         printf("\n3.Quit the program\n");
            printf("\n\nYour Choice?");
        scanf("%d",&choice);
             printf("\nEnter one data item after each prompt. Press return after each one."); 
             printf("\nEnter -1 with  when you are done with data input.\n\n");
           
       switch(choice)
         {
         case 1:
              readData(data,count);
              break;
     
       case 2:
      
      printf("\nGiven data: \n");
                
        printf("%.2f ",data[i]);
        printf("\n\nTotal no of data items: %d",count);
        printf("\nHighest value in the data: %.2f",max(data,count));
        printf("\nLowest value in the data: %.2f",min(data,count));
        printf("\nMean: %.2f",mean(data,count));
        printf("\nMedian: %.2f",median(data,count));
        printf("\nStandard Deviation: %.2f",sd(data,count));
        printf("\nVariance: %.2f\n\n",pow((sd(data,count)),2));
        break;
         
       case 3:exit(0);
                                        }
     }while(1);
     
      
     getchar();
     return 0;
    }
    
    
    void readData(float data[],int count)
    {
         float value;
         
          
         printf("Item #%d:\t",count+1);
          scanf("%f",&value);
                           
    while((value) != EOF)
      {
       
        printf("Item #%d:\t",count+1);
          scanf("%f",&value);
          
      }
    }
    
    float mean(float *data,int count)
    {
     int i;
      float mean=0.0;
       for(i=0;i<count;i++)
       mean+=data[i];
      return mean/count;
                }
    
    float sd(float data[],int count)
    {
      float avg=mean(data,count);
      float SD=0.0;
       int i;
       for(i=0;i<count;i++)
       {
         SD+= pow((data[i]-avg),2);
         }
        return sqrt(SD/count);
    }
    
    float max(float data[],int count)
     {
        int i=0;
        float max=data[0];
                           
        for(i=0;i<count;i++)
         if(max<data[i])
           max=data[i];
           
           
        return max;
                }
    
    float min(float data[],int count)
    {
        int i=1;
        float min=data[0];
       
        for(i =0;i<count;i++)
        
        if(min>data[i])
        min=data[i];
        return min;
                }
                
                
    float median(float data[],int count)
    {
        int i,j;
         float tmp;
       for(i=0;i<count-1;i++)
         for( j=i+1;j<count;j++)
            if(data[i]>data[j])
    {
          tmp=data[i];
             data[i]=data[j];
             data[j]=tmp;
          }
           if(count%2==0)
             return (data[count/2-1]+data[count/2])/2;
           else
             return data[count/2];
                 }

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    How/where are you actually storing your data in the array?
    Code:
    void readData(float data[],int count)
    {
         float value;
         
          
         printf("Item #%d:\t",count+1);
          scanf("%f",&value);
                           
    while((value) != EOF)
      {
       
        printf("Item #%d:\t",count+1);
          scanf("%f",&value);//this stores to local variable value
          
      }
    }
    Plus, its int main(void) and you need to return (0) at the end of main as I am sure you have been told here before.
    Last edited by AndrewHunter; 07-28-2011 at 12:32 AM.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Display system menu
    By silverAG in forum Windows Programming
    Replies: 1
    Last Post: 02-17-2009, 09:42 PM
  2. Help display ***** for the value of an int
    By GUIPenguin in forum C++ Programming
    Replies: 12
    Last Post: 02-04-2005, 07:02 AM
  3. Display
    By bnd98 in forum C++ Programming
    Replies: 4
    Last Post: 04-07-2003, 12:08 AM
  4. how to display a .jpg
    By Noobie in forum C++ Programming
    Replies: 10
    Last Post: 02-23-2003, 06:09 PM
  5. How to modify a menu into a menu Folder(contains submenus) ??
    By L.O.K. in forum Windows Programming
    Replies: 3
    Last Post: 01-09-2003, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21