Thread: "Expected declaration or statement at end of input"

  1. #1
    Registered User levitylek's Avatar
    Join Date
    Sep 2010
    Location
    Orlando
    Posts
    19

    "Expected declaration or statement at end of input"

    For starters this program is far from finished, I just completed the first option of my menu and I wanted to test it out but when I compile it, all the way at the very end with the last } I get an error saying "Expected declaration or statement at end of input". I've tried fooling around with more brackets, returning 0, and a bunch of other stuff but I can't figure out why it won't let me compile it. Also I'm just learning functions and still pretty bad with them so don't be surprised if there's all kinds of other crazy stuff wrong :P

    Code:
    #include <stdio.h>
    #define PI 3.14159
    #define INCHES_IN_MILE 63360
    
    void printmenu();
    void tripfueleff();
    void printrating ();
    void getitem();
    void printlogo();
    void printfuelgraph();
    
    int main(){
    
    		int ans;
    		
    		//Get user's input
    		menu();
    		scanf("%d", &ans);
    
    		while (ans !=6) {
    			
    			if (ans==1) {
    				tripfueleff();
    
    
    
    }
    
    		
    //Prints out menu
    void menu() {
    	printf("Which of the following options would you like?\n");
    	printf("1) Calculate fuel efficiency for a trip.\n");
    	printf("2) Determine whether or not to go back home and pick up an item.\n");
    	printf("3) Print the car logo to the display.\n");
    	printf("4) Play the multiplication game.\n");
    	printf("5) Print a visual display of the recent fuel efficiency.\n");
    	printf("6) Quit\n");
    }
    //Calculates fuel efficiency
    void tripfueleff() {
    	int revs, totalrevs, rad, pass=1, time, time1=0, time2=5, interval1, interval2, finalmpg;
    	double gas, totalgas, mpg, dist, totaldist;
    	
    	//User Input
    	printf("How long was your trip in minutes?\n");
    	scanf("%d", &time);
    	
    	printf("What is the radius of your tires, in inches?\n");
    	scanf("%d", &rad);
    	
    	//Determine 5 minute intervals
    	interval1 = (time / 5);
    	interval2 = (time / 5);
    	
    	while (interval1 > 0) {
    		
    		printf("During time interval #%d, how many revolutions did your car's tires make?\n", pass);
    		scanf("%d", &revs);
    		
    		totalrevs = totalrevs + revs;
    		
    		printf("During time interval #%d,how many gallons of gas did your car use?\n", pass);
    		scanf("%lf", &gas);
    		
    		totalgas = totalgas + gas;
    		
    		pass++;
    		
    		//Calculate mpg
    		
    		dist = ((rad*2*PI)*(revs)) / INCHES_IN_MILE;
    		mpg = dist/gas;
    		time1 = time1 + 5;
    		time2 = time2 + 5;
    		
    		printf("Time %d-%d minutes: Your car averaged %.2lf miles per gallon\n", time1, time2, mpg);
    		interval1--;
    	}
    	
    	totaldist = ((rad*2*PI)*(totalrevs)) / INCHES_IN_MILE;
    	finalmpg = totaldist / totalgas;
    	
    	printf("For the whole trip, your car averaged %d mpg.\n", finalmpg);
    }

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    "Fooling around with more brackets..."?

    Don't fool around, just make sure that every left bracket has a matching right bracket. Now look carefully at your main function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM