Thread: Must Be Missing Something Simple!

  1. #1
    Registered User
    Join Date
    May 2018
    Posts
    3

    Must Be Missing Something Simple!

    First, this is NOT for a class. It is NOT homework. I used to write some C code and am trying to remember how to do it - and have written this simple example. I have other examples that work just fine but this one tells me that the function (line 72 and 73) is trying to define a function. I declare the function on line 29 and call it on line 56. I have looked and looked at this - what am I doing wrong???

    I get miles per hour from the keyboard.

    Please be gentle, I think I just have "brain lock".

    Code:
    //
    //  main.c
    //  boys_program
    //
    //  Created by Charles Phillips on 6/8/18.
    //  Copyright (c) 2018 Charles Phillips. All rights reserved.
    //
    
    
    #include <stdio.h>
    // declare variables
    int miles_cl_sealy = 60;  // this is set for now
    int miles_sealy_luling = 45;  // set for now
    int miles_luling_LaCantera = 70;  // set for now
    
    
    // mph from stop to stop, variables
    int mph_cl_sealy = 30;   // we will enter this
    int mph_sealy_luling = 40;  // enter this
    int mph_luling_LaCantera = 50;  // enter this
    
    
    // time from stop to stop, variables
    int time_cl_sealy = 1;  // set initial value (hours) then calculate it
    int time_sealy_luling = 2;  // set initial value
    int time_luling_LaCantera = 3;  // set initial value
    int time_cl_LaCantera = 40;  // set initial value, addition of times for "legs" gives final
    
    
    int time_cl_austin = 2;  // set initial value hours, will be calculated
    
    
    // functions
    int find_time_cl_LaCantera(int mph_cl_sealy, int mph_sealy_luling, int mph_luling_LaCantera); // declare function
    
    
    int main(void)
    
    
    {
        printf("So You Want To Go Relax For A Week???\n");
    
    
        char answer = 'x';  // define answer and give it a default value
        // miles from stop to stop, not a variable
    
    
        while (answer != 'q') {
            printf("\nWhat do you want to do? Enter the letter for your response.\n\n");
            printf(" a) Austin\n");
            printf(" b) La Cantera\n");
            printf(" q) Quit\n\n");
    
    
        scanf(" %c", &answer);
        
        switch (answer) {
            case 'a':
                printf("Do you want to spend a week in Austin??\n");
    
    
                printf("Your driving time is: %d minutes\n", time_cl_austin);
                break;
            case 'b':
                printf("Do you want to spend a week in LaCantera??\n");
    
    
                time_cl_LaCantera = find_time_cl_LaCantera (<#int mph_cl_sealy#>, <#int mph_sealy_luling#>, <#int mph_luling_LaCantera#>);  // call function
                printf("Now We Have To Find The Best Route\n");
            
                break;
            case 'q':
                printf("You said to quit so I will quit\n");
                break;
            default:
                printf("Invalid selection. Try again.\n");
                break;
        }
    
    
        return 0;
        }
        
        int find_time_cl_LaCantera(int mph_cl_sealy, int mph_sealy_luling, int mph_luling_LaCantera)
          {
            printf("Do you want to spend a week at La Cantera??\n");
            printf("Debug - initial time Clear Lake to La Cantera %d \n", time_cl_LaCantera);
            printf("What speed is allowed from Clear Lake to Sealy?\n");
            printf("debug - time Clear Lake to Sealy before calculation %d\n", time_cl_sealy); // debug
            scanf(" %d", &mph_cl_sealy);  // from keyboard
            time_cl_sealy = miles_cl_sealy / mph_cl_sealy;  // hours to sealy    }
            
            printf("What speed is allowed from Sealy to Luling?\n");
            printf("debug - time Sealy to Luling before calculation %d\n", time_sealy_luling); // debug
            scanf(" %d", &mph_sealy_luling);  // from keyboard
            time_sealy_luling = miles_sealy_luling / mph_sealy_luling;
            
            printf("What speed is allowed from Luling to La Cantera?\n");
            printf("debug - time Clear Lake to Sealy before calculation %d\n", time_luling_LaCantera); // debug
            scanf(" %d", &mph_luling_LaCantera);  // from keyboard
            time_luling_LaCantera = miles_luling_LaCantera / mph_luling_LaCantera;
            time_cl_LaCantera = time_cl_sealy + time_sealy_luling + time_luling_LaCantera;
            
            printf("time from Clear Lake to Sealy, after calculation %d hours\n", time_cl_LaCantera);
            return time_cl_LaCantera;   // this is what the function generates
    
    
    
    
        }
    }

  2. #2
    Registered User
    Join Date
    May 2018
    Posts
    3
    This is odd - the system here numbers the lines differently than the one I have???? It inserts blank lines.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,554
    Well it looks like the brace on line 48 isn't matched properly.

    Or the brace on the last line is badly out of position.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    May 2018
    Posts
    3
    Oh - the brace on 111 was extra. And I noticed that I had screwed up line 68 but had already fixed it. Too much caffeine or not enough! It is working now, the error I got did not indicate the actual problem. Thanks!!
    Last edited by CharlesHouston; 06-12-2018 at 02:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am i missing?
    By pipskie in forum C Programming
    Replies: 8
    Last Post: 11-26-2012, 07:09 PM
  2. Replies: 4
    Last Post: 09-23-2011, 09:58 AM
  3. I know I am missing something simple plz help
    By iamnewtothis in forum C++ Programming
    Replies: 8
    Last Post: 03-11-2011, 08:30 AM
  4. Replies: 4
    Last Post: 07-14-2010, 07:13 AM
  5. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM

Tags for this Thread