Very Simple C Error

This is a discussion on Very Simple C Error within the C Programming forums, part of the General Programming Boards category; Okay, I am just starting out in C and I am having a problem with this very basic script: Code: ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    18

    Very Simple C Error

    Okay, I am just starting out in C and I am having a problem with this very basic script:

    Code:
    /* Darko Stamenic
    1/14/2010
    Experiment */
    
    #include <stdio.h>
    
    // set known values
    #define YARDS_IN_MILE 1760;
    #define FEET_IN_YARD 3;
    
    int main(void) {
        
        // declare integers
        int feet_in_mile, miles_ran, yards_ran, feet_ran;
        
        // calculate feet in mile
        feet_in_mile = YARDS_IN_MILE*FEET_IN_YARD;
        
        // print Hello World
        printf("Hello world\n");
        
        // ask for the users input of how many miles they ran
        printf("How many miles did you end up running?\n");
        scanf("%d", &miles_ran);
        if (miles_ran >= 10000) {
                      printf("You could not have ran that much!\n");
                      } else {
        // calculate how many yards and feet were run depending on user's input
        yards_ran = miles_ran*YARDS_IN_MILE;
        feet_ran = miles_ran*feet_in_mile;
        
        // display how many yards and feet in a mile and how many yards or feet the user ran
        printf("There are %d yards in a mile or %d feet in a mile =D\n",YARDS_IN_MILE,feet_in_mile);
        printf("You ran %d yards, or %d feet!\n",yards_ran,feet_ran);
    }
        // pause and end program
        system("PAUSE");
        return 0;
    
    }
    The problem is that I get an error on like 17, which is where it calculates feet in a mile. It all worked fine until I tried to use #define instead of int. What could I be doing wrong? I cannot find it

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You're just like me, you want to put semi-colons at the end of #define lines.

    *Don't do that* !

    Remove the semi-colons.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    18
    How did I know it was going to be such an easy solution =D

    Thank you very much for your help. I just could not see it for the life of me!

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I've done the same. Creatures of habit, we are.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. Linking to shlwapi.lib in C, MSVC CMD.
    By Joerge in forum Windows Programming
    Replies: 4
    Last Post: 08-07-2009, 05:18 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

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