125k views
5 votes
Write a single statement that prints outsideTemperature with 2 digits in the fraction (after the decimal point). End with a newline. Sample output with input 103.45632: 103.46

User AndPat
by
5.8k points

1 Answer

3 votes

Answer:

The program to this question can be described as follows:

program:

#include <iostream> //defining header file

#include <iomanip> //defining header file

using namespace std;

int main() //defining main method

{

double outsideTemperature; //defining double variable

outsideTemperature= 103.45632; //initializing the value in variable

cout<<outsideTemperature<<": "<<setprecision(2)<<fixed<<outsideTemperature; //print value

return 0;

}

Output:

103.456: 103.46

Step-by-step explanation:

Description of the code:

In the above code first include the header file for using the "setprecision" method.

In the next line, the main method is declared, inside the method, a double variable "outsideTemperature" is declared, that initialized with a float value.

Inside this method, "setprecision" method is called, which is the predefined method, that prints two-point value after the decimal point.

User Whisht
by
5.4k points