banner



What Is Fixed Point Notation

C++ Fixed Point Annotation

At that place are iii types of Nutrient at a Stadium.

1) Hotdog costs $5
two) Drink costs $4
3) Nacho Hats costs $12
Write a program that asks how many of each blazon of food were sold, then displays the amount of income generated from food sales. Format your dollar amount in fixed-point notation, with two places of precision, and exist sure to the decimal point it always displayed.

I need aid with the above question and how to use fix precision?

Thanks,

Kirk

Fixed betoken precision is just saying that the first northward digits of a number vest to the right side of the decimal betoken.

Your program expects n==2. So:

1234 ways 12.34
76 means 0.76
500 means 5.00

To get the whole part, use sectionalisation: 500 / 100 = 5.
To get the 'partial' office, use residual: 567 % 100 = 67.

To make C++ display things properly, you'll need the setw() and setfill() manipulators:

                          1
ii
3
four
5
6
7
eight
9
10
11
12
13
xiv
15
                                                      // Fill empty spaces with zeros.                            // (you only need to call this one once, somewhere at the first of your program)                            cout << setfill('0');                            // Print a number as 0.00                            cout << whole_part <<                            "."                            << setw(ii) << fractional_part <<                            "\n";                            // Print the number 0.00                            cout << 0 <<                            "."                            << setw(2) << 0 <<                            "\n";                            // Print the number fifty.84                            cout << 50 <<                            "."                            << setw(2) << 84 <<                            "\n";                            // Print $5.00                            cout <<                            "$"                            << 5 <<                            "."                            << setw(2) << 0 <<                            "\n";                        

Hope this helps.

[edit] Oh, don't forget to #include <iomanip>

Last edited on

Topic archived. No new replies allowed.

What Is Fixed Point Notation,

Source: https://cplusplus.com/forum/beginner/174328/

Posted by: boothfrass1954.blogspot.com

0 Response to "What Is Fixed Point Notation"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel