CS 150 Introduction to C++ Programming - Spring 1998 

[ Home | Lecture Notes| WebTutor | WebTutor Site Map]


Formatting Output for Floating Point Numbers


The output of numbers is controlled by IO Manipulators. Two common manipulators for the output are

Given that "x" is a float variable and x = 14.3827, show the output of each statement below (include blanks as appropriate!).

  1. cout << "x is" << setw(5) << setprecision(2) << x;

  2. cout << "x is" << setw(8) << setprecision(2) << x;

  3. cout << "x is" << setw(0) << setprecision(2) << x;

  4. cout << "x is" << setw(7) << setprecision(3) << x;

 

Choose one when done
   

Copyright chris wild 1998.
For problems or questions regarding this web contact [Dr. Wild (e-mail:wild@cs.odu.edu].
Last updated: February 04, 1998.