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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter9: Records (struct)
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

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 <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 }

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT