//Example: setprecision, fixed, showpoint
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
int main()
{
double x,y,z;
float A = 9 ;
string Temp = "Hello";
x = 15.673;
y = 235.736;
z = 9525.9864765;
cout <<"\n\t\tUsing fixed, showpoint(to show the trailing 0's), \n\t\t\tshowpos (to show + sign): \n" ;
cout <<"\t\t\t, setw(20), setprecision(2),and right\n " <<endl ;
cout <<showpoint<< showpos << right ;
cout <<"x"<< setw(15) <<"y"<< setw(15) <<"z"<< setw(15) <<"A"<< setw(15) <<"Temp"<< endl;
cout << x << setw(15) << y << setw(15) << z << setw(15) << A << setw(15) << Temp << endl ;
cout << "press enter to continue: " ;
cin.get();
return 0;
}
I still don't know if I did it right or not, since we were supposed to modify a code given from the professor. Originally, it is setw(20), but I changed it to 15. Not sure if that was allowed or not.
Now, I don't know how to show the correct number of digits for those values. I tried using setprecision, but it didn't work for all of them. Showpoint gave me an error, I guess I am not using them correctly.