OS: Win 2K Environment: Desktop
I cannot get this program to display the figures in the last
two rows correctly. See the different results I obtained.
If I take out the "scientific" notation code out the result
will even get worse.
----------------- - - - - - - -
My codes:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
cout.setf(ios::fixed | ios::scientific);
static double values[] = {1.23, 35.44, 653.70, 4358.224};
static char* names[] = {"zoot", "Jimmy", "Al", "Stan"};
for (int i=0; i < 4; i++)
{
// commented codes not good for use
//cout << setiosflags(ios::left | ios::showpoint);
//cout << setw(6) << names[i] << endl;
//cout << resetiosflags(ios::left);
//cout << setiosflags(ios::right);
//cout << setw(10) << values[i] << endl;
cout.setf(ios::left);
cout << setw(6);
cout << names[i];
cout << resetiosflags(ios::left);
//cout.setf(ios::fixed | ios::right | ios::showpoint);
cout.setf(ios::fixed | ios::right);
// cout.setf(ios::right);
cout << setw(11)
//<< setprecision(2)
<< values[i]
<< endl;
}
return 0;
} // end of main
--=-=-=-=-=-=-=-
Result without using setprecision 2 and showpoint:
zoot 1.23000
Jimmmy 35.4400
Al 653.700
Stan 4358.22
Press any key to continue
-------
Result with set precision 2 and showpoint:
zoot 1.2
Jimmmy 35.
Al 6.5e+002
Stan 4.4e+003
Press any key to continue
----------
================================
Result without showpoint:
zoot 1.2
Jimmmy 35
Al 6.5e+002
Stan 4.4e+003
Press any key to continue
------------------
Result without showpoint and setprecision. Got good result
here except the trailing zero from Al amount is missing
and the figures of the last two lines aren't lined up properly.
zoot 1.23
Jimmmy 35.44
Al 653.7
Stan 4358.22
Press any key to continue