Thread: Conflicting types error

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    9

    Conflicting types error

    Edit: So I was getting the error "Conflicting types for 'order_weight'" within my itemShipping function but I realized I was missing the brackets around it (not yet corrected in the following code). Now that I have fixed that my program will compile and run but when going trying to use that function (menu option 1) it only returns 0.00. Does anyone see why this may be happening?

    Code:
    #include <stdio.h>
    
    #define QUIT 6
    #define TAX_RATE 0.065
    
    void printmenu();
    double itemShipping(double price, double weight, int quantity, int tax);
    double weightChange(int minWalk, int minStand, int minDrink, int minEat);
    void rollerCoaster(int trackLength, int maxTrainLength, int* pMaxPeople, int* pNumCars);
    void printHeartDesign(int size, int ch);
    void ucfidol(FILE* ifp);
    
    
    int main () 
    {
        int ans; 
        
        //display menu and read the user's choice
        printf("\n");
        printmenu();
        scanf("%d", &ans);
        
        //continue until the user quits
        while (ans != QUIT) {
              
              //execute user's choice
              if (ans == 1){
                  double price, weight;
                  int quantity, tax;
                 printf("What is the cost of the item to be purchased (in dollars)?\n");
                 scanf ("%lf", &price);
        
                 printf("What is the weight of the item (in pounds)?\n");
                 scanf ("%lf", &weight);
        
                 printf("How many of the item are you purchasing?\n");
                 scanf ("%d", &quantity);
        
                 printf("Is the item a taxed item? (1=yes, 0=no)\n");
                 scanf ("%d", &tax);
                 
                 //calculate result and print
                 itemShipping (price, weight, quantity, tax);
                 
                 printf("Your total purchase, with shipping, will cost $%.2lf.\n", itemShipping);
               }
                
                
              else if (ans == 2)
              printf("%d", ans);
                 //weightChange ();
                 
                 
                 
              else if (ans == 3)
              printf("%d", ans);
                 //rollerCoaster ();
              else if (ans == 4)
              printf("%d", ans);
                 //printHeartDesign ();
              else if (ans == 5)
              printf("%d", ans);
                 //ucfidol (FILE* ifp);
              else if (ans != 6)
                   printf("This is an invalid choice. Please try again.\n");
                   
              //read the user's next choice
              printf("\n");
              printmenu();
              scanf("%d", &ans);
        }
    
       // system("PAUSE");
        return 0;
    }
    
    /* Pre-condition: None
    Post-condition: Prints the menu.
    */
    void printmenu() {
         
         printf("Which of the following options would you like?\n");
         printf("1) Gift Shop Shipping\n");
         printf("2) Calorie Counter Application\n");
         printf("3) Roller Coaster Design\n");
         printf("4) Printing a Heart T-shirt\n");
         printf("5) UCF Idol\n");
         printf("6) Quit\n");
    }
        
        
    /* 
    Pre-condition: price, weight: a positive real numbers less than 100.
                    quantity: a positive integer less than 100.
                    tax: 0(if not taxed), 1(if taxed)
    Post-condition: Given the four pieces of information as specified in
                    Program 2A, this function returns the total cost of
                    the corresponding order with shipping included.
    */
    double itemShipping(double price, double weight, int quantity, int tax);
           double order_weight, ship;
    
    //calculate order weight
        order_weight = weight * (double)quantity;
    
        //determine shipping cost per pound     
        ship = 4;
    
        if (order_weight >= 10) 
                        ship = 2.5;
     
        if (order_weight >= 30) 
                        ship = 1.5;
    
        if (order_weight >= 50 )
                        ship = .99;
    
    
        //calculate price before tax          
        double sub_total = (order_weight * ship) + (price * quantity);
        //calculate total price of order
        double total_cost = sub_total * (1 + tax * TAX_RATE);
        
        return total_cost;
    
    
    /*
    Pre-conditions: All four parameters are non-negative integers less
                    than 720.
    Post-conditions: Returns the weight change (in pounds) of the person
                    who walked, stood, drank and ate for the number of
                    minutes designated, using the calculation from
                    Program 2B.
    */
    double weightChange(int minWalk, int minStand, int minDrink, int minEat);
    
    
    
    
    /*
    Pre-condition: trackLength is positive and less than 10000.
                   maxTrainLength is in between 10 and 100, inclusive.
                   pMaxPeople points to a variable that will store the
                   maximum number of people for this train design.
                   pNumCars points to a variable that will store the
                   number of cars per train in the ideal design as
                   specified in Program 2C.
    Post-condition: The variables pointed to by pMaxPeople and pNumCars
                    will store the maximum number of people and the number
                    of cars per train for this design, respectively.
    */
    void rollerCoaster(int trackLength, int maxTrainLength, int* pMaxPeople, int* pNumCars);
    
    
    
    /* 
    Pre-condition: size is in between 3 and 10 inclusive.
    Post-condition:A heart with the given size will be printed, as
                     defined in Program 3B with the character ch.
    */
    void printHeartDesign(int size, int ch);
    
    
    
    /* 
    Pre-condition: ifp points to the beginning of a file that stores data
                   about UCF Idol shows, as specified in Program 4.
    Post-condition: The results of all the shows in the file will be
                    printed to the screen and FILE pointed to by ifp will
                    be closed.
    */
    void ucfidol(FILE* ifp);
    Last edited by mastrxplodr; 04-11-2011 at 06:29 PM.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Thank you for denying everyone else the chance to learn...

    Next time, add the correction... don't delete the problem.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    well it's not working correctly anyway so I'll repost.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    9
    The version of this code that doesn't return the conflicting types error is as follows

    Code:
    #include <stdio.h>
    
    #define QUIT 6
    #define TAX_RATE 0.065
    
    void printmenu();
    double itemShipping(double price, double weight, int quantity, int tax);
    double weightChange(int minWalk, int minStand, int minDrink, int minEat);
    void rollerCoaster(int trackLength, int maxTrainLength, int* pMaxPeople, int* pNumCars);
    void printHeartDesign(int size, int ch);
    void ucfidol(FILE* ifp);
    
    
    int main () 
    {
        int ans; 
        
        //display menu and read the user's choice
        printf("\n");
        printmenu();
        scanf("%d", &ans);
        
        //continue until the user quits
        while (ans != QUIT) {
              
              //execute user's choice
              if (ans == 1){
                  double price, weight;
                  int quantity, tax;
                 printf("What is the cost of the item to be purchased (in dollars)?\n");
                 scanf ("%lf", &price);
        
                 printf("What is the weight of the item (in pounds)?\n");
                 scanf ("%lf", &weight);
        
                 printf("How many of the item are you purchasing?\n");
                 scanf ("%d", &quantity);
        
                 printf("Is the item a taxed item? (1=yes, 0=no)\n");
                 scanf ("%d", &tax);
                 
                 //calculate result and print
                 itemShipping (price, weight, quantity, tax);
                 
                 printf("Your total purchase, with shipping, will cost $%.2lf.\n", itemShipping);
               }
                
                
              else if (ans == 2)
              printf("%d", ans);
                 //weightChange ();
                 
                 
                 
              else if (ans == 3)
              printf("%d", ans);
                 //rollerCoaster ();
              else if (ans == 4)
              printf("%d", ans);
                 //printHeartDesign ();
              else if (ans == 5)
              printf("%d", ans);
                 //ucfidol (FILE* ifp);
              else if (ans != 6)
                   printf("This is an invalid choice. Please try again.\n");
                   
              //read the user's next choice
              printf("\n");
              printmenu();
              scanf("%d", &ans);
        }
    
       // system("PAUSE");
        return 0;
    }
    
    /* Pre-condition: None
    Post-condition: Prints the menu.
    */
    void printmenu() {
         
         printf("Which of the following options would you like?\n");
         printf("1) Gift Shop Shipping\n");
         printf("2) Calorie Counter Application\n");
         printf("3) Roller Coaster Design\n");
         printf("4) Printing a Heart T-shirt\n");
         printf("5) UCF Idol\n");
         printf("6) Quit\n");
    }
        
        
    /* 
    Pre-condition: price, weight: a positive real numbers less than 100.
                    quantity: a positive integer less than 100.
                    tax: 0(if not taxed), 1(if taxed)
    Post-condition: Given the four pieces of information as specified in
                    Program 2A, this function returns the total cost of
                    the corresponding order with shipping included.
    */
    double itemShipping(double price, double weight, int quantity, int tax){
           double order_weight, ship;
    
    //calculate order weight
        order_weight = weight * (double)quantity;
    
        //determine shipping cost per pound     
        ship = 4;
    
        if (order_weight >= 10) 
                        ship = 2.5;
     
        if (order_weight >= 30) 
                        ship = 1.5;
    
        if (order_weight >= 50 )
                        ship = .99;
    
    
        //calculate price before tax          
        double sub_total = (order_weight * ship) + (price * quantity);
        //calculate total price of order
        double total_cost = sub_total * (1 + tax * TAX_RATE);
        
        return total_cost;
    }
    
    /*
    Pre-conditions: All four parameters are non-negative integers less
                    than 720.
    Post-conditions: Returns the weight change (in pounds) of the person
                    who walked, stood, drank and ate for the number of
                    minutes designated, using the calculation from
                    Program 2B.
    */
    double weightChange(int minWalk, int minStand, int minDrink, int minEat);
    
    
    
    
    /*
    Pre-condition: trackLength is positive and less than 10000.
                   maxTrainLength is in between 10 and 100, inclusive.
                   pMaxPeople points to a variable that will store the
                   maximum number of people for this train design.
                   pNumCars points to a variable that will store the
                   number of cars per train in the ideal design as
                   specified in Program 2C.
    Post-condition: The variables pointed to by pMaxPeople and pNumCars
                    will store the maximum number of people and the number
                    of cars per train for this design, respectively.
    */
    void rollerCoaster(int trackLength, int maxTrainLength, int* pMaxPeople, int* pNumCars);
    
    
    
    /* 
    Pre-condition: size is in between 3 and 10 inclusive.
    Post-condition:A heart with the given size will be printed, as
                     defined in Program 3B with the character ch.
    */
    void printHeartDesign(int size, int ch);
    
    
    
    /* 
    Pre-condition: ifp points to the beginning of a file that stores data
                   about UCF Idol shows, as specified in Program 4.
    Post-condition: The results of all the shows in the file will be
                    printed to the screen and FILE pointed to by ifp will
                    be closed.
    */
    void ucfidol(FILE* ifp);

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Looks like itemShipping() function was missing opening brace in the original. How’s it going now? Program runs OK?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: conflicting types for 'sbp_pos_lookup_1'
    By gerger in forum C Programming
    Replies: 7
    Last Post: 10-05-2010, 11:44 AM
  2. Error! Conflicting Types
    By davewang in forum C Programming
    Replies: 5
    Last Post: 12-05-2008, 08:47 AM
  3. error: conflicting types for 'basename'
    By samf in forum C Programming
    Replies: 3
    Last Post: 09-20-2007, 09:22 AM
  4. error: conflicting types
    By Rodman in forum C Programming
    Replies: 5
    Last Post: 03-10-2006, 04:20 AM
  5. Conflicting types of typedef error
    By advocation in forum C++ Programming
    Replies: 4
    Last Post: 03-22-2005, 06:26 PM