// types4.cc  P. Conrad  CISC181 Spring 2007
// a C++ program to demonstrate various types of variables

// This program also shows what happens when you use setprecision
// on float and double values---and shows that floating point numbers
// are often not exact.

// This program is the same as types3, but the value used is 3.75 instead
// of 3.6.   Note the difference in program behavior.  
// What is the explanation for this difference?  

// Hint 1: It have anything to do with "powers of two" and "binary"
// Hint 2: It has something to do with "negative powers",
//         For example, two raised to the -1 power.

#include <iostream>
#include <iomanip> // for setw
using namespace std;

int main()
{
  // declare some simple scalar variables, initializing them 
  // as you declare them.

  float f = 3.75;
  double d = 3.75;
  
  // print them out, along with their sizes

  cout << "f=" << setw(5) << f << " sizeof i=" << sizeof f << endl;
  cout << "d=" << setw(5) << d << " sizeof i=" << sizeof d << endl; 

  // then print them with various values for setprecision

  
  cout << "with setprecision(2) f=" << setprecision(2) << f << endl;
  cout << "with setprecision(2) d=" << setprecision(2) << d << endl;
  cout << endl;

  cout << "with setprecision(5) f=" << setprecision(5) << f << endl;
  cout << "with setprecision(5) d=" << setprecision(5) << d << endl;
  cout << endl;


  cout << "with setprecision(10) f=" << setprecision(10) << f << endl;
  cout << "with setprecision(10) d=" << setprecision(10) << d << endl;
  cout << endl;


  cout << "with setprecision(30) f=" << setprecision(30) << f << endl;
  cout << "with setprecision(30) d=" << setprecision(30) << d << endl;
  cout << endl;



  return 0;

}

