Thread: boolean/function call help

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    Post boolean/function call help

    Can someone please aid me in finding solutions and help fixing the errors in my program.
    The object is to calculate a parking fee with various vehicle types at different times.
    Any help is appreciated.

    Code:
    #include <stdio.h>
    #include <stdbool.h>
    
    /* Constants */
    #define car 5                    /* vehicle */
    #define motorbike 2              /* vehicle */
    #define truck 10                 /* vehicle */
    
    /* function prototypes */
    char validateVehicleType(int c, int m, int t);
    float validateParkingTime(float h);
    float getParkingFee(int c, int m, int t, float h);
    float displayParkingFee(int c, int m, int t, float h);
    
    int main (void)
    {
       /* declare variables */
          float h;              /* hrs */
    	  
    	  /* Validate vehicle type. */
    	  printf("Enter your vehicle type:");
    	  scanf("%c");
    	  
    	  /* Display vehicle type */
    	  if ( vehicle type == c || m || t)
    	     printf("%d\n");
    	  else if ( vehicle type != c || m || t)
    	     printf("Wrong vehicle type");
    		 
    	  /* Validate parking time */
    	  printf("Enter parking time (hours):");
    	  scanf("%f", &hrs);
    	  
    	  /* Display parking time */
    	  if ( parking time >= 0.0)
    	     printf("%f\n");
    	  else if ( parking time < 0.0)
    	     printf("Wrong parking time");
    		 
    	  /* Get parking fee */
    	  parking_fee = getParkingFee(int c, int m, int t, float h);
    	  
    	  /* Display parking fee */
    	  printf("Parking_fee = %.2f\n", dollars);
    	  
    }
    
          /* function definitions */
    	  
    	  float displayParkingFee(int c, int m, int t, float h);
    {
    	        return ((c || m || t)*h);
    			if (h>4 && h<=12)
    			   return("(parking_fee)*0.75 %.2f\n", dollars);
    			else if (h>12)
    			   return("(parking_fee)*0.5 %.2f\n", dollars);
    			else if (h<4)
    			   return(0);
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    What part isn't working?

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Right off the bat I'd say
    Code:
    scanf("%f", &hrs);
    should be
    Code:
    scanf("%f", &h);

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    104
    Quote Originally Posted by bithub View Post
    What part isn't working?
    ^...

  5. #5
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by jma619 View Post
    Can someone please aid me in finding solutions and help fixing the errors in my program.
    The object is to calculate a parking fee with various vehicle types at different times.
    Any help is appreciated.

    Code:
    #include <stdio.h>
    #include <stdbool.h>
    
    /* Constants */
    #define car 5                    /* vehicle */
    #define motorbike 2              /* vehicle */
    #define truck 10                 /* vehicle */
    
    /* function prototypes */
    char validateVehicleType(int c, int m, int t);
    float validateParkingTime(float h);
    float getParkingFee(int c, int m, int t, float h);
    float displayParkingFee(int c, int m, int t, float h);
    
    int main (void)
    {
       /* declare variables */
          float h;              /* hrs */
    	  
    	  /* Validate vehicle type. */
    	  printf("Enter your vehicle type:");
    	  scanf("%c");
    	  
    	  /* Display vehicle type */
    	  if ( vehicle type == c || m || t)
    	     printf("%d\n");
    	  else if ( vehicle type != c || m || t)
    	     printf("Wrong vehicle type");
    		 
    	  /* Validate parking time */
    	  printf("Enter parking time (hours):");
    	  scanf("%f", &hrs);
    	  
    	  /* Display parking time */
    	  if ( parking time >= 0.0)
    	     printf("%f\n");
    	  else if ( parking time < 0.0)
    	     printf("Wrong parking time");
    		 
    	  /* Get parking fee */
    	  parking_fee = getParkingFee(int c, int m, int t, float h);
    	  
    	  /* Display parking fee */
    	  printf("Parking_fee = %.2f\n", dollars);
    	  
    }
    
          /* function definitions */
    	  
    	  float displayParkingFee(int c, int m, int t, float h);
    {
    	        return ((c || m || t)*h);
    			if (h>4 && h<=12)
    			   return("(parking_fee)*0.75 %.2f\n", dollars);
    			else if (h>12)
    			   return("(parking_fee)*0.5 %.2f\n", dollars);
    			else if (h<4)
    			   return(0);
    }
    1.you have not given arguments to many of the printf and scanf functions.
    2. use uppercase letters for symbolic constants to differentiate them from normal variables.
    3.you have defined only one function out of the four declared.
    4.keep in mind the precedence of opeartors while using them in the if statements.it can lead to wrong outputs.
    5.your return statements are also wrong.
    6.return 0 at the end of the main function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. minix system call pls help for project
    By porvas in forum Linux Programming
    Replies: 2
    Last Post: 06-14-2009, 02:40 AM
  2. Error C2664 - Trying to call an external Dll
    By jamez05 in forum C++ Programming
    Replies: 3
    Last Post: 08-08-2006, 06:07 AM
  3. Class won't call
    By Aalmaron in forum C++ Programming
    Replies: 3
    Last Post: 04-13-2006, 04:57 PM
  4. Iterative Tree Traversal using a stack
    By BigDaddyDrew in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2003, 05:44 PM
  5. call by reference and a call by value
    By IceCold in forum C Programming
    Replies: 4
    Last Post: 09-08-2001, 05:06 PM