SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
C++ Basics
Exercise:
Self-test Exercises
Question:10 | ISBN:9780321531346 | Edition: 7

Question

What statements should you include in your program to ensure that, when a number of type double is output, it will be output in ordinary notation with three digits after the decimal point?

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

PROGRAM CODE:

#include <iostream>
#include <iomanip>
using namespace std;

int main() 
{
    double number = 123.456789; // Replace this with your double value
    //Prompt input statement
    cout<<"Given number"<<number<<endl;
    // Set the precision to three digits after the decimal point
   cout <<fixed <<setprecision(3);
    
    // Output the number in ordinary notation with three digits after the decimal point
   cout <<"The ordinary notation with three digits after the decimal point: " <<number <<endl;

    return 0;
}

OUTPUT:

Given number123.456789
The ordinary notation with three digits after the decimal point: 123.457

 

 

0 0

Discussions

Post the discussion to improve the above solution.