home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list3_2.c < prev    next >
C/C++ Source or Header  |  1993-10-16  |  929b  |  32 lines

  1. /* Demonstrates variables and constants */
  2. #include <stdio.h>
  3. /* Define a constant to convert from pounds to grams */
  4. #define GRAMS_PER_POUND 454
  5. /* Define a constant for the start of the next century */
  6. const int NEXT_CENTURY = 2000;
  7. /* Declare the needed variables */
  8. int weight_in_grams, weight_in_pounds;
  9. int year_of_birth, age_in_2000;
  10.  
  11.  
  12. main()
  13. {
  14.        /* Input data from user */
  15.  
  16.        printf("Enter your weight in pounds: ");
  17.        scanf("%d", &weight_in_pounds);
  18.        printf("Enter your year of birth: ");
  19.        scanf("%d", &year_of_birth);
  20.  
  21.        /* Perform conversions */
  22.  
  23.        weight_in_grams = weight_in_pounds * GRAMS_PER_POUND;
  24.        age_in_2000 = NEXT_CENTURY - year_of_birth;
  25.  
  26.        /* Display results on the screen */
  27.  
  28.        printf("\nYour weight in grams = %d", weight_in_grams);
  29.        printf("\nIn 2000 you will be %d years old", age_in_2000);
  30.        return 0;
  31.    }
  32.