getting NOT A FUNCTION error

This is a discussion on getting NOT A FUNCTION error within the C Programming forums, part of the General Programming Boards category; Hey, I got this program where I have to write simple functions to calculate the time and cost for a ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    6

    getting NOT A FUNCTION error

    Hey, I got this program where I have to write simple functions to calculate the time and cost for a roadtrip. I keep on getting errors on the travelTime() and travelcost() functions. The errors are error C2063: 'travelTime' : not a function and error C2063: 'travelcost' : not a function. Here is my code and any help would be appreciated.

    Code:
    #include <stdio.h>
    
    #define MINUTES 60;
    
    /*function prototype*/
    int roundUp(float);
    float travelTime(int, int, int);
    float travelcost(int, int, float, float);
    
    /*Main Function*/
    int main()
    {
    
    
    	/*declaire variables*/
    	int miles, carGasMileage, gasTankSize = 15, averageSpeed, restTime;
    	float pricePerGall = 1.40, travelTime, travelcost, fillupTimes, mealCost;
    
    	/*Get miles variable*/
    	printf("How many miles are you going to travel?: ");
    	scanf("%d", &miles);
    	
    
    	/*Get car gas mileage*/
    	printf("\nWhat is the gas mileage that your car gets?: ");
    	scanf("%d", &carGasMileage);
    
    	/*Get average speed*/
    	printf("\nWhat is the average spped that you want to travel in mph units?: ");
    	scanf("%d", averageSpeed);
    
    	/*Get rest time--NOTE I had to eliminate the Brother rest time for this program-There had to be only one rest time*/
    	printf("\nHow many minutes do you plan on resting?: ");
    	scanf("%d", &restTime);
    	
    	/*Get meal cost*/
    	printf("\nHow much will you spend on meals?: ");
    	scanf("%f", &mealCost);
    
    	/*clear screen*/
    	system("cls");
    
    	/*calculate the time*/
    	travelTime(miles, averageSpeed, restTime);
    
    	/*calculate the cost*/
    	travelcost(miles, carGasMileage, pricePerGall);
    
    	
    
    	/*calculate the times that they will need to fill-up*/
    	fillupTimes = (miles / carGasMileage) / (gasTankSize * 7/8);
    	roundUp(fillupTimes);
    
    	/*display RoadTrip Results*/
    	printf("So, you're taking a trip to the Beach?\n");
    	printf("Are you interested in how long it is going to take?\n");
    	printf("It will take %5.0f minutes\n\n", travelTime);
    
    	printf("Dude, Do you want to know how much it is going to cost?\n");
    	printf("It will cost $%4.2f\n\n", travelcost);
    
    	
    
    	printf("You are going to have to fill up %3.2f times on your way there.\n\n", fillupTimes);
    
    
    	return 0;
    }
    
    int roundUp()
    {
    	float a1, a2;
    	int b1;
    
    	
    	
    	b1 = a1;
    	a2 = a1 - b1;
    
    	if (a2 > 0.) b1++;
    	
    	
    	
    	
    	return (b1);
    }
    
    
    float travelTime()
    {
    	int miles, averageSpeed, restTime;
    	float time;
    	
    	if (miles > 0){
    	time = (miles / averageSpeed) * MINUTES + restTime;
    	}
    	else 
    		printf("You didn't go anywhere!");
    
    
    	return (time);
    }
    
    float travelcost()
    {
    	int miles, carGasMileage;
    	float pricePerGall = 1.40, cost, mealCost;
    
    	if (miles > 0){
    		cost = (miles / carGasMileage) * pricePerGall + mealCost;
    	}
    	else 
    		printf("You didn't go anywhere!");
    
    	return (cost);
    }

  2. #2
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    You cant give a function name and a variable name the same name!
    Code:
    #include <stdio.h>
    
    #define MINUTES 60;
    
    /*function prototype*/
    int roundUp(float);
    float travelTime(int, int, int);
    float travelcost(int, int, float, float);
    
    /*Main Function*/
    int main()
    {
    
    
    	/*declaire variables*/
    	int miles, carGasMileage, gasTankSize = 15, averageSpeed, restTime;
    	float pricePerGall = 1.40, travelTime, travelcost, fillupTimes, mealCost;
    Last edited by stumon; 03-31-2003 at 09:31 PM.

  3. #3
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    You also will want to add a '&' to your average speed scanf() and if you want to pass those variables when calling those 2 functions, you will need to have to 2 functions receive them. Right now, you prototype them to, but they dont in the function definition. You are also not passing the correct amount of variable to travelCost(). You ask for 4, but only send 3.
    Code:
    float travelTime(int miles, int averageSpeed, int restTime)
    {
    	float time;
    	
    	if (miles > 0){
    	time = (miles / averageSpeed) * MINUTES + restTime;
    	}
    	else 
    		printf("You didn't go anywhere!");
    
    
    	return (time);
    }
    
    float travelcost(int miles, int carGasMileage, float pricePerGall, float mealCost)
    {
    	if (miles > 0){
    		cost = (miles / carGasMileage) * pricePerGall + mealCost;
    	}
    	else 
    		printf("You didn't go anywhere!");
    
    	return (cost);
    }
    I am sorry but i think you may want to take down these examples and start from scratch with your function calls, prototypes, variable names, and what you pass. Use the code you have to get an idea, and make sure you are passing the correct amount of variables and make sure you will need to pass them, something that only needs to be used in 1 function does not need to be declared in main and passed to something. Also, make sure you do not name functions and variables the same thing. Be a little bit more careful, i recommend commenting on code.
    Last edited by stumon; 03-31-2003 at 09:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM

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