Question: C . Using printf / scanf In this program, you will add two user entered heights in feet'inches format ( eg: 5 ' 1 0

C. Using printf/scanf
In this program, you will add two user entered heights in feet'inches" format (eg: 5'10') and print the sum of the two heights in the feet'inches" format as well as in centimeters. Write your C++ program called Lab3C.cpp that does the following:
Prompt for and read in first height using printf and scanf appropriately. Use integer variables to store feet and inches for the first height (feet1 and inches 1). You need to use the correct format specifier in scanf to scan the two values. Hint: See lecture slide coding examples (Chapter 2).
Prompt for and read in second height using printf and scanf appropriately. Use integer variables to store feet and inches for the second height (feet2 and inches2).
Compute the sum of the two user entered heights.
For calculating sum in feet'inches" format, add two feet and two inches of the two heights in two integer variables (totalFeet and totalinches). Also, compute the carryover after you sum the inches of the two heights because 1 foot =12 inches. For example, if user enters 5'8'' and 5'7' for first and second heights respectively, then the sum should be 11'3'' instead of 10'15''.
Hint: Although you may use different techniques to solve this problem, you can use integer division operation (/) to the sum of inches to get the carryover part and add the carryover to the total feet. Also, apply modulo operation (%) to the sum of inches to compute the total inches.
3
CSCE 1030 Lab03
For calculating sum in centimeters (use floating point variable totalCenti), you can use the following formula (note: 1 foot =30.48 centimeters and 1 inch =2.54 centimeters):
totalCenti = totalFeet **30.48+ totalinches **2.54
Print the summation of the two heights in feet'inches" and centimeters units using printf function:
Display centimeters with precision of 2(i.e., two digits after dot).
Sample outputs:
$./a.out
Enter first height (format: 5'10"): 5'9"
Enter second height (format: 5'10"): 4'8"
Sum of two heights =10'5(317.50 centimeters)
$./a.out
Enter first height (format: 5'10") : 5'4"
Enter second height (format: 5'10"): 5'3"
Sum of two heights =1017(322.58 centimeters)
 C. Using printf/scanf In this program, you will add two user

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!