-1

My program won't compile correctly. It gives undefined errors. Can someone help me solving that? It says

C:\Users\Milan_2\AppData\Local\Temp\ccQt3lVs.o In function 'orderOnConveyer': 90 C:\Users\Milan_2\Desktop\Untitled2.c undefined reference to 'insert'

C:\Users\Milan_2\AppData\Local\Temp\ccQt3lVs.o In function 'WTandTAT': 115 C:\Users\Milan_2\Desktop\Untitled2.c undefined reference to 'isEmpty' C:\Users\Milan_2\AppData\Local\Temp\ccQt3lVs.o In function 'main':

#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#define MAX1 30
#define MAX2 30
#define TRUE 1
#define FALSE 0

struct cake{
    char cake;
    int preperation_time;
    int baking_time;
    int waiting_time;
    int turnaround_time;
};
struct Queue{
    int front;
    int rear;
    int count;
    struct cake items[MAX1];
};
struct Stack{
    int top;
    struct cake items[MAX2];
};

struct cake ChocolateCake();
struct cake SpongeCake();
struct cake MeringueCake();
struct cake RedVelvetCake();

void orderOnConveyer(struct Queue *, int);
void WTandTAT(struct Queue *,struct Queue *, int);
int longestBakingTime(struct Queue *q);
void orderOnStorageConveyer(struct Queue *, struct Stack *);
void averageWaitingTime_and_averageTurnaroundTime(struct Queue *, struct Queue *);

void init(struct Queue *);
int isFull(struct Queue *);
void insert(struct Queue *, struct cake);


void push(struct Stack *, struct cake);

struct cake pop(struct Stack *);

struct cake ChocolateCake(){
     struct cake c;
     c.cake='C';
     c.preperation_time=25;        
     c.baking_time=40;             
     c.waiting_time=0;
     c.turnaround_time=0;
     return c;
}
struct cake SpongeCake(){
     struct cake c;
     c.cake='S';
     c.preperation_time=30;
     c.baking_time=20;           
     c.waiting_time=0;
     c.turnaround_time=0;
     return c;
}
struct cake MeringueCake(){
     struct cake c;
     c.cake='M';
     c.preperation_time=45;
     c.baking_time=75;           
     c.waiting_time=0;
     c.turnaround_time=0;
     return c;
}
struct cake RedVelvetCake(){
     struct cake c;
     c.cake='R';
     c.preperation_time=60;
     c.baking_time=30;          
     c.waiting_time=0;
     c.turnaround_time=0;
     return c;
}

void orderOnConveyer(struct Queue *q, int minute){
     int i;
     printf("\n\n\n\n----------Conveyer Order----------\n\n\n");
     for(i=1;i<=minute;i++){
         if(i%25==0){
            printf("\nChocolate Cake");
            insert(q, ChocolateCake());
         }
         if(i%30==0){
            printf("\nSponge Cake");
            insert(q, SpongeCake());
         }
         if(i%45==0){
            printf("\nMeringue Cake");
            insert(q, MeringueCake());
         }
         if(i%60==0){
            printf("\nRedVelvet Cake");
            insert(q, RedVelvetCake());
         }
     }    
}


void WTandTAT(struct Queue *q, struct Queue *q1, int minute){
         struct cake temp;
         int i,temp1=0,temp2=0,temp3=0,temp4=0;

         printf("\n\n\n------- Waiting Time & Turnaround Time for each cake -------\n\n");
         printf("Cake\tWaiting Time\tTurnaround Time");

         while(!isEmpty(q)){


         if(temp.preperation_time==25){

              for( i=temp.preperation_time+temp1;i<minute;i++){
                  temp.waiting_time++;   
         }
              temp1=temp1+temp.preperation_time;
              temp.turnaround_time=temp.baking_time+temp.waiting_time;
              insert(q1, temp);   
         }

         else if(temp.preperation_time==30){

              for( i=temp.preperation_time+temp2;i<minute;i++){
                  temp.waiting_time++;    
              }

              temp2=temp2+temp.preperation_time;
              temp.turnaround_time=temp.baking_time+temp.waiting_time;

              insert(q1, temp);

         }
         else if(temp.preperation_time==45){

              for( i=temp.preperation_time+temp3;i<minute;i++){
                  temp.waiting_time++; 
              }

              temp3=temp3+temp.preperation_time;
              temp.turnaround_time=temp.baking_time+temp.waiting_time;

              insert(q1, temp);

         }
         else if(temp.preperation_time==60){

              for( i=temp.preperation_time+temp4;i<minute;i++){
                  temp.waiting_time++;  
          }

              temp4=temp4+temp.preperation_time;
              temp.turnaround_time=temp.baking_time+temp.waiting_time;

              insert(q1, temp);

         }
         }

}


void averageWaitingTime_and_averageTurnaroundTime(struct Queue *q, struct Queue *q1)
 {
      struct cake temp;
      int Total_waiting_time=0, count=q->count, Total_turnaround_time=0;
      float avgWT=0, avgTAT=0;
      while(!isEmpty(q)){



            Total_waiting_time=Total_waiting_time+temp.waiting_time;
            avgWT=(Total_waiting_time/count);

            Total_turnaround_time=Total_turnaround_time+temp.turnaround_time;
            avgTAT=(Total_turnaround_time/count);
            insert(q1,temp);
      }
      printf("\n\n------------------------------------------------------------------------");        
      printf("\n\nAvarage Waiting Time =  %f min",avgWT);
      printf("\n\nAvarage Turnaround Time =  %f min",avgTAT);            
}


main(){
     struct Queue q;
     struct Queue q1;
     struct Stack s;
     struct cake temp;
     int minute, i=0;

     s.top=-1; 
     init(&q); 
     init(&q1);

     printf("*******************Welcome Bakery Simulation*******************");
     printf("\n\t\t       Author : Milan Udayanga( )");
     printf("\n--------------------------------------------------------------------------------");

     printf("\n\nEnter the duration(minute) for check the process in the bakery:");
     scanf("%d",&minute);



    orderOnConveyer(&q, minute);

    WTandTAT(&q, &q1, minute);

    while(!isEmpty(&q1)){

        printf("\n%c\t%d\t\t%d", temp.cake, temp.waiting_time, temp.turnaround_time);
        insert(&q,temp);
   }

    averageWaitingTime_and_averageTurnaroundTime(&q, &q1);

    orderOnStorageConveyer(&q1, &s);

    while(!isEmpty(&s)){
        temp= pop(&s);
        printf("\n%c",temp.cake);

   }
    getch();
    return 0;
}
alk
  • 69,737
  • 10
  • 105
  • 255
Kingsman
  • 11
  • 1
  • 1
  • 4
  • In addition to the errors, I also get 5 *warnings* you need to pay attention to. – Jongware May 29 '15 at 11:30
  • i just want to execute the program . this won't execute at least . – Kingsman May 29 '15 at 11:44
  • It won't *compile*, which is something else. The compiler tells you why it cannot compile your code, and since those errors apparently did not mean anything to you, they were explained in more detail. Other than with that, we cannot help you either. – Jongware May 29 '15 at 13:25

1 Answers1

2

In your code,

  1. For insert() function, you have only declared the function (as a prototype). You did not define the function here. You need to have a function definition in place.

  2. For isEmpty(), you have neither a declaration nor a definition. It's not known to the compiler what to do in that case. So, it says, "undefined reference".

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • 1
    `isEmpty` should also give a warning that the function was not declared. So OP probably has earlier error/warning messages that have been ignored. – M.M May 29 '15 at 11:25
  • @MattMcNabb I also think so. The error log posted by OP ends _unexpectedly_. – Sourav Ghosh May 29 '15 at 11:35
  • How should it be ? . give an example ? – Kingsman May 29 '15 at 11:42
  • 1
    @MilanUdayanga what how? errror log? error message should have some more lines, which you did not post here. – Sourav Ghosh May 29 '15 at 11:44
  • Can you just correct that code . i just want to execute the program . after that i can correct other errors . – Kingsman May 29 '15 at 11:49
  • 1
    @MilanUdayanga How can I correct something which is _missing_? You need to write those two functions to make it compile. BTW, you're not having another source file containing those two definitions, are you? – Sourav Ghosh May 29 '15 at 11:51