Need some help to fix a declaration syntax error

This is a discussion on Need some help to fix a declaration syntax error within the C Programming forums, part of the General Programming Boards category; I am new to programming and am trying to finish this project for my class. not sure where my error ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Location
    Hawthorne, California, United States
    Posts
    9

    Need some help to fix a declaration syntax error

    I am new to programming and am trying to finish this project for my class. not sure where my error is here, can someone help point it out
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>  
    
    
    int displayMenu();
    int getData(int * a, int n);
    void input();
    void display();
    float mean1(float[],int);  
    float median1(float[],int);  
    float mode1(float[],int);  
    double standarddeviation1(float array[],int n)
    
    
    int main()
    {
      int com;
      srand(time(NULL));
      do{
         com=displayMenu();
         switch (com)
         {
           case 1 : input(); break;
           case 2 : display(); break;
           case 3 : printf("have a nice day\n");break;
           default : printf("Bad data Try again\n");
          }
          
          }while(com !=3);
    
    
    return 0;
    
    
    }
    
    
    
    
    int displayMenu()
    {
       int c;
       printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
       printf("@  1. Enter data          @\n");
       printf("@  2. Display data        @\n");
       printf("@  3. Quit                @\n");
       printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
       printf("Enter your choice:");
       scanf("%d",&c);
       return c ;
     }
     
     void input()
     {
        int i,n,choice;  
        float array[200],mean,median,mode;  
        double standarddeviation;
        
        switch(choice)  
        {  
            case 1: mean=mean1(array,n);  
                printf("\n\tMean = %f\n",mean);  
                break;  
            case 2: median=median1(array,n);  
                printf("\n\tMedian = \n",median);  
                break;  
            case 3: mode=mode1(array,n);  
                printf("\n\tMode = %f\n",mode);  
                break;   
            case 4: standarddeviation=standarddeviation1(array,n);  
                printf("\n\tStandard deviation = %f\n",standarddeviation); 
                break;  
            case 5: break;  
            default:printf("Wrong Option");  
                break;  
        }  
    
    
        while(choice!=5);  
        getchar(); 
    return 0;
    }
      
    int getData(int * a, int n)
    {
      int i;
      i=n;
      printf("Enter item#%d>>",i+1);
      while(scanf("%d",&a[i])!=EOF)
      {
        i++;
        printf("Enter item#%d>>",i+1);
      } 
    
    
      return i;
    }      
    
    
    void display()
    {
     printf("is not done\n");
    } 
    float mean1(float array[],int n) 
    {  
        int i;  
        float sum=0;  
        for(i=0;i<n;i++)  
        sum=sum+array[i];  
    return (sum/n);  
    }  
    
    
    
    
    float median1(float array[],int n) 
    {  
        float temp;  
        int i,j;  
        for(i=n-1;i>=0;i--)  
            for(j=0;j<i;j++)  
                if(array[j]>=array[j+1])  
                {  
                    temp=array[j];  
                    array[j]=array[j+1];  
                    array[j+1]=temp;  
                }  
    
    
        if(n%2==0)  
            return (array[n/2]+array[n/2-1])/2;  
        else  
            return array[n/2];  
    }  
    
    
    float mode1(float array[],int n) 
    {  
        return (3*median1(array,n)-2*mean1(array,n));  
    }  
    
    
    double standarddeviation1(float array[],int n) 
    {  
        int j;   
        double max[100],sum,variance,mean;  
        mean=mean1(array,n);  
        sum=0;  
        for(j=0;j<n;j++)   
        {  
            max[j]=pow((array[j]-mean),2);  
            sum+=max[j];  
        }  
        variance=sum/(j-1);   
        return sqrt(variance);  
    }

  2. #2
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    65
    what is an error, are you getting?
    I mean, did the code gets compiled without error?

  3. #3
    Registered User
    Join Date
    Feb 2012
    Location
    Hawthorne, California, United States
    Posts
    9
    When i ran the compiler I get E2141 declaration syntax error

  4. #4
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    65
    post your compiler error details, with line no

  5. #5
    Registered User
    Join Date
    Feb 2012
    Location
    Hawthorne, California, United States
    Posts
    9
    Error E2141 statistic.c 15: Declaration Syntax error

  6. #6
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    65
    Refer line no 13, function declaration.
    you forget the ;
    Note: Please cross check your input function, 'choice' is not initialized.

  7. #7
    Registered User
    Join Date
    Feb 2012
    Location
    Hawthorne, California, United States
    Posts
    9
    ok, thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error "in function 'main' syntax error before 'int' Help Please
    By blackhat11907 in forum C Programming
    Replies: 5
    Last Post: 08-20-2011, 07:05 PM
  2. Little bit of variable declaration syntax
    By TheNexumMan in forum C Programming
    Replies: 4
    Last Post: 11-25-2008, 03:35 AM
  3. GCC compiler giving syntax error before 'double' error
    By dragonmint in forum Linux Programming
    Replies: 4
    Last Post: 06-02-2007, 05:38 PM
  4. Expression/Declaration Syntax Errors
    By fuh in forum C++ Programming
    Replies: 2
    Last Post: 01-15-2003, 05:49 PM
  5. Declaration Syntax Error
    By Im_no_Bjarne in forum C++ Programming
    Replies: 5
    Last Post: 01-25-2002, 05:38 AM

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