Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that: (a) declares a variable X for storing a floating point number and initializes it with zero. (b) asks the user

Write a C++ program that: (a) declares a variable X for storing a floating point number and initializes it with zero. (b) asks the user to input a floating point number with 6 digits : 3 digits in whole number part and 3 digits in decimal part. (c) read user-input value and store it in X. (d) print digits in different positions of the X (hundreds, tens, ones, tenths, hundredths and thousandths) in the format shown in the sample output. Use tabs and newlines to mimic the format. (e) round user-input value stored in X and store the result it in X. (f) print out the rounded value. (Please do not use loops, the program should be as simple as possible.)

Sample Output

Input a floating-point number with 6 digits (3 in whole number part and 3 in decimal part i.e. XXX.XXX) 456.789

The decimal part:

thousandths: 9

hundredths: 8

tenths: 7

The whole number part:

ones : 6

tens : 5

hundreds : 4

Rounded value : 457

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

More Books

Students also viewed these Databases questions