Demonstrates variables and constants
Posted by JanWan
Last Updated: March 02, 2012
/*Demonstrates variables and constants*/

/*Define a constant to convert from pounds to grams*/
#define GRAMS_PER_POUND 454

/*Define a constant the start of the next century*/
const int NEXT_CENTURY = 2050;

/*Declare the needed variables */
long weight_in_grams,weight_in_pounds;
int year_of_birth, age_in_2050;

/*Input data from user*/

printf("Enter your weight in pounds:");
scanf("%d", &weight_in_pounds);
printf("Enter your year of birth:");
scanf("%d", &year_of_birth);

/* Preform conversions */

weight_in_grams = weight_in_pounds * GRAMS_PER_POUND;
age_in_2050 = NEXT_CENTURY - year_of_birth;

/* Display results on the screen */

printf("\nYour weight in grams = %ld", weight_in_grams);
printf("\nIn 2050 you will be %d years old\n", age_in_2050);

return 0;
Related Content