expected declaration or statement at end of input

This is a discussion on expected declaration or statement at end of input within the C Programming forums, part of the General Programming Boards category; Hi all. I'm new to programming just cannot get this to compile. I would appreciate any help you could give ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    3

    Unhappy expected declaration or statement at end of input

    Hi all. I'm new to programming just cannot get this to compile. I would appreciate any help you could give me. I'm sure there is plenty wrong other than whats keeping it from compiling, but if I could at least get it compiled I would feel better.

    I get expected declaration or statement at end of input error for line 170, which is the very last line. Any ideas what is causing this? Thanks for your time.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int read_location (double *latitude, double *longitude);
    void print_location (double latitude, double longitude);
    double distance (double lat1, double lon1, double lat2, double lon2);
    void sort_arrays (double arr1[], double arr2[], double arr3[], int size);
    void all_distances (double latRef, double lonRef, const double lat_list[],const double lon_list[], double dist_list[], int size);
    
    
    int main ()
    {
    
    double lat[20], lon[20], dist[20];
    double refLat, refLon;
    int choice, quitProg, size, count;
    
      printf ("Welcome to the latitude and longitude sorter.\n You may enter up to 20 locations.\n Enter a latitude of 99 when done.");
      quitProg = 1;
      size = 0;
      while (size < 20 && quitProg != 0){
        quitProg = read_location ((lat+size), (lon+size));
        size++;
      } //end while
    
      printf ("You have finished entering values.\n\n");
      choice = 0;
      while (choice != 1){
        Printf ("1 to quit\n2 to sort by latitude\n3 to sort by longitude\n4 to sort by distance");
        scanf ("%d", &choice);
    
        switch (choice) {
          case 1:
            break;
          case 2:
            sort_arrays (lat, lon, dist, size);
            for (count = 0; count < size; count++){
    	  print_location (lat[count], lon[count]);
            } // end for
            break;
          case 3:
            sort_arrays (lon, lat, dist, size);
            for (count=0; count<size; count++){
    	  print_location (lat[count], lon[count]);
            } // end for
            break;
          case 4:
            printf ("Please enter reference latitude and longitude:\n");
            scanf ("%lf %lf", &refLat, &refLon);
            all_distances (refLat, refLon, lat, lon, dist, size);
            sort_arrays (dist, lat, lon, size);
            for (count=0; count<size; count++){
    	  print_location (lat[count], lon[count]);
              printf (" is %f miles from reference\n", dist[count]);
            } // end for 
            break;
          default:
            printf ("Not a valid entry. Please choose again.\n\n");
            break;
       } //end while
    
    printf ("Thank you for using the latitude and longitude sorter.");
    return 0;
    
    } //end main
    
    /*____________________________________________________________________________________*/
    
    int read_location (double *latitude, double *longitude){
    
    double latEntry  = 0;
    double lonEntry = 0;
      while (latEntry != 99){
        printf ("Please enter a latitude and longitude:\n");
        scanf ("%lf %lf", &latEntry, &lonEntry);
        if (fabs(latEntry) <= 90 && fabs(lonEntry) <= 180) {
          *latitude = latEntry;
          *longitude = lonEntry;
        } else {
          printf ("\n");
        } //end else
        return 1;
      } //end while
    return 0;
    
    } //end read_location
      
    /*____________________________________________________________________________________*/
    
    void print_location (double lat, double lon){
    
      if (lat >= 0){
        printf ("%f North ", lat);
      } else {
        printf ("%f South ", lat);
      }
      if (lon <= 0){
        printf ("%f West\n", lon);
      } else {
        printf ("%f East\n", lon);
      }
    
    } //end print_location
    
    /*____________________________________________________________________________________*/
    
    double distance (double lat1, double lon1, double lat2, double lon2){
    double dist;
    dist = (3963 * acos(cos(lon1-lon2)*cos(lat1)*cos(lat2) + sin(lat1)*sin(lat2)));
    return dist;
    
    }
    
    /*____________________________________________________________________________________*/
    
    void sort_arrays(double arr1[], double arr2[], double arr3[], const int size){
      int pass, i;
      double hold;
      for (pass = 0; pass < size-1; pass++) {
        for (i = 0; i < size-1; i++) {
          if (arr1[i] > arr1[i+1]) {
    	hold = arr1[i];
    	arr1[i] = arr1[i+1];
    	arr1[i+1] = hold;
    	hold = arr2[i];
    	arr2[i] = arr2[i+1];
    	arr2[i+1] = hold;
    	hold = arr3[i];
    	arr3[i] = arr3[i+1];
    	arr3[i+1] = hold;
          } //end if
        } //end iterations for loop
      } // end passes for loop
    
    }  //end sort_arrays
    
    /*____________________________________________________________________________________*/
    
    void all_distances(const double latRef, const double lonRef, const double lat_list[], const double lon_list[], double dist_list[], const int size){
      int count;
      for (count = 0; count < size-1; count++){
        dist_list[count] = distance (lat_list[count], lon_list[count], latRef, lonRef);
        count++;
      } //end for
    
    } //end all_distances

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    3
    Sorry, I forgot to close the switch. Any other advise would surely be welcome though, as long as it's posted.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,670
    You've mispelled printf as Printf (remember, C is case-sensitive). You're also missing a closing brace at the end of main. It might help to line up your brackets like so:

    Code:
    void foo(void)
    {
    	while(condition)
    	{
    		switch(ch)
    		{
    		
    		}
    	}
    }
    It makes it easier to match them up, anyway.



    ITSA
    Socket Library!

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    3
    Thanks. I found those and got it to compile. I think my main problem now is pointers and arrays. It runs, but I always get an erroneous 0.00000 by 0.00000 entry in the lat and lon arrays. Also, the distance array isn't populating right. I'll keep working on it.

    Thanks again.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,670
    >> It runs, but I always get an erroneous 0.00000 by 0.00000 entry in the lat and lon arrays.

    They populated fine for me. Can you give an example input where this happens?

    >> printf (" is %f miles from reference\n", dist[count]);

    printf thinks you're passing it a float. Use the %g specifier, or similar.

    >> for (count = 0; count < size-1; count++)

    It looks like the loop isn't going far enough. Why are you subtracting 1 from 'count'?

    >> dist = (3963 * acos(cos(lon1-lon2)*cos(lat1)*cos(lat2) + sin(lat1)*sin(lat2)))

    Remember, + has a lower precedence than *, so you'll want to put the two subexpressions in parenthesis.



    ITSA
    Socket Library!

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,456
    %f should work for both doubles and floats...
    Floats are, in fact, promoted to doubles when passed to printf anyway.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 08:29 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

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