Thread: Need help on Linked Error

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    16

    Need help on Linked Error

    I’ve been working on this program and can’t solve the errors.
    The correct output should be –


    Enter Subject Code : BKG 121313
    Enter Subject Name : C Programming Class
    Enter Total No of Student : 1

    ------------------------------------
    STUDENT 1
    ------------------------------------
    Quiz 1 <5m> : 3.5
    Quiz 2 <5m> : 4.2
    Quiz 3 <5m> : 1.6
    Assignment 1 <15m> : 12.4
    Assignment 2 <15m> : 13.2
    Midterm Test <20m> : 18.3
    Final Exam <50m> : 46.5
    ------------------------------------
    STUDENT 1 DETAILS
    ------------------------------------
    Quiz Mark : 6.20 [Details: Quiz 1 : 3.5 , Quiz 2 = 4.2 , Quiz 3 : 1.6]
    Assignment marks [20m] : 17.07[Details: Assignment 1 : 12.4, Assignment 2 : 13.2 ]
    Midterm test marks [20m]: 18.30
    Final Exam marks [50m] : 46.50
    Total Marks : 88.07
    Grade : A




    This is my code -

    Code:
    #include<stdio.h>
    #include<string.h>
    float calculate_quiz();
    float calculate_assignment();
    void dipslay(float quizm[], float assignment[], float midterm, float final, char grade, int j);
    
    void main()
    {
         char code[10], name[15];
         int number, i, A, B, C , F;
         float midterm, final, quizm, assignment, total_mark;
         char grade;
         
         //declaration
         
         printf("\nEnter Subject Code: ");
         gets(code);
         printf("\nEnter Subject Name: ");
         gets(name);
         printf("\nEnter Total No Of Student: ");
         scanf("%d", &number);
         
         for (i=1; i<=number; i++)
         {
             quizm=calculate_quiz();
             assignment=calculate_assignment();
             
             printf("\nEnter Midterm Test Mark: ");
             scanf("%f", &midterm);
             printf("\nEnter Final Exam Mark: ");
             scanf("%f", &final);
             
             total_mark=quizm+assignment+midterm+final;
             
             //nested if
             if(total_mark>=75)
             {
                  grade='A';
                  A++;
             }
             
             else if(total_mark >= 60 && total_mark <=75)
             {
                  grade='B';
                  B++;
             }
             
             else if(total_mark >= 60 && total_mark <=60)
             {
                  grade='C';
                  C++;
             }
             
             else
             {
                 grade='F';
                 F++;
             }
             //end of nested if
             
             display(quizm,assignment,midterm,final,grade,i);
             
         }
         //end of main
         
         float calculate_quiz()
         {
               float total=0, quiz[0];
               int m ;
                          
               for (m=0; m<3; m++)
               {
                printf("\nQuiz %d <5M>: ", (m+1));
                scanf("%f", &quiz[m]);
                total = total + quiz[m];
               }       
                
                return ((total/15)*10);
         }
         //end calculate quiz
         
         float calculate_assignment()
         {
               float total_mark=0,assignment[0];
               int x;
               
               for (x=0 ; x<2 ; x++)
               {
                  printf("\nQuiz %d <15M>: ", (x+1));
                  scanf("%f", &assignment[x]);
                  total_mark= total_mark + assignment[x];   
               }
               return ((total_mark/30)*20);
         }
    
         //end calculate assignment
         
         void dipslay(float quizm[], float assignment[], float midterm, float final, char grade, int i)
         {
             int j;
                      
             printf ("\n----------------------------");
             printf ("\n student %d details ", (i+1));           
             printf ("\nQuiz Mark [10M]: %2.f ", quizm);
             
             for (i=0 ; i<3 ; i++)
             {
                 printf ("\nQuiz %d = %.2f ", quizm[j]);
                 printf ("\nQuiz %d = %.2f ", j , quizm[j]);
             }
          
             for (j=0 ; j<2 ; j++)
             {
                     printf ("\nAssignment %d = %.2f ", assignment[j]);
                     printf ("\nAssignment %d = %.2f ", j , assignment[j]); 
             }    
    
    
    getch();
    
    }
    }


    There are errors appear on:

    In fuction ‘main’
    • [Linker error] undefined reference to `calculate_quiz'
    • [Linker error] undefined reference to `calculate_assignment'
    • [Linker error] undefined reference to `display'
    Id returned 1 exit status




    Looking forward for your response
    Thx!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Take all of those function assignments out of your main function. Also, you might want to make them before your main function, or at least prototype them up top, so that when you want to call them, it actually knows what they are.

    You can't make functions inside of other functions. They must be their own block:
    Code:
    void foo( void )
    {
        ...do stuff...
    }
    
    int main( void )
    {
        ...do stuff...
    }
    Not:
    Code:
    int main( void ){
        void foo( void )
        {
            ...do stuff...
        }
    
    }
    See?

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM