Complete listing of Formatting 01

 

/* File: Formatting01.cpp
Copyright 2006, Richard G. Baldwin

Illustrates formatted output and the inclusion of <iomanip>

Shows how to format floating-point output to two decimal
digits.

The output is:

10 divided by 3 to two decimal digits is: 3.33
**********************************************************/

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

int main(){
  cout << setprecision(2) << fixed << showpoint;
  cout << "10 divided by 3 to two decimal digits is: " 
                                               << 10.0/3.0;

  return 0;
}//end main

Listing 8