Code 2.2 is for a program that demonstrates variable declarations and the use of literal and symbolic constants. The program prompts the user to input his/her weight (in grams) and year of birth. The program then calculates and displays the user’s weight (in pounds) and his/her age during the RIO Olympics year (2016). Type the code, compile (F9), and run (F10) Code 2.2. Save it as varsandconts.c. Answer the following: 1. What are the two symbolic constants used? 2. Show two methods of defining a symbolic constant named MAXIMUM that has a value of 100. Provide the correct syntax. 3. Give an advantage of using a symbolic constant over a literal constant. Code 2.2. A program that demonstrates the use of variables and constants. 1 /* Demonstrates variables and constants */ 2 #include 3 4 #define GRAMS_PER_POUND 454
Code 2.2 is for a
1. What are the two symbolic constants used?
2. Show two methods of defining a symbolic constant named MAXIMUM that has a
value of 100. Provide the correct syntax.
3. Give an advantage of using a symbolic constant over a literal constant.
Code 2.2. A program that demonstrates the use of variables and constants.
1 /* Demonstrates variables and constants */
2 #include <stdio.h>
3
4 #define GRAMS_PER_POUND 454
5
6 const int RIO_YEAR = 2016;
7
8 long weight_in_grams, weight_in_pounds;
9 int year_of_birth, age;
10
11 int main()
12 {
13
14 printf(“Enter weight (in grams): ”);
15 scanf(“%ld”, &weight_in_grams);
16
17 printf(“Enter your year of birth: ”);
18 scanf(“%d”, &year_of_birth);
19
20 weight_in_pounds = weight_in_grams / GRAMS_PER_POUND;
21 age = RIO_YEAR – year_of_birth;
22
23 printf(“\n\nYour weight in pounds is %d”, weight_in_pounds);
24 printf(“\nAge during the RIO Olympics year: %d.”, age);
25
26 return 0;
27 }
Step by step
Solved in 2 steps