Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

More Books

Students also viewed these Databases questions

Question

=+2. Which of the following best describes negative reinforcement?

Answered: 1 week ago