/* DemoDatatypes2.cpp CIS 150 5/29/2008 David Klick This program shows the range of the floating point data types. The output will differ depending on what compiler is used. */ #include #include using std::cin; using std::cout; using std::endl; void cont(); int main(void) { // declare and initialize variables float minFloat = FLT_MIN; float maxFloat = FLT_MAX; double minDouble = DBL_MIN; double maxDouble = DBL_MAX; long double minLDouble = LDBL_MIN; long double maxLDouble = LDBL_MAX; // display internal sizes of data types cout << "A float is " << sizeof(float) << " bytes long\n"; cout << "A double is " << sizeof(double) << " bytes long\n"; cout << "A long double is " << sizeof(long double) << " bytes long\n"; // display minimum and maximum values of datatypes cout << "float: " << minFloat << " through " << maxFloat << endl; cout << "double: " << minDouble << " through " << maxDouble << endl; cout << "long double: " << minLDouble << " through " << maxLDouble << endl; cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press Enter to continue..."; cin.get(); return; } /* Note: This sample run was done with a compiler that clearly has a problem with long doubles. Sample output: A float is 4 bytes long A double is 8 bytes long A long double is 12 bytes long float: 1.17549e-038 through 3.40282e+038 double: 2.22507e-308 through 1.79769e+308 long double: 0 through 1.#INF Press Enter to continue... */