In the code below I have used setw(10) which means field width is 10. Does decimal point also constitute part of field width? If it does, then "1234567.00" is 10 characters long.
Why is there an error in the output?
How can I reset the output to normal?
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
float fpn;
cout << "enter the number: ";
cin >> fpn;
cout << setiosflags(ios::fixed) //fixed (not exponential)
<< setiosflags(ios::showpoint) //always show decimal point
<< setprecision(2) //two decimal places
<< setw(10) //field width 10
<< fpn << endl; //finally, the number
cout << "enter the number again: ";
cin >> fpn;
cout << fpn << endl << endl;
system("pause");
return 0;
}
OUTPUT:
enter the number: 123456789 1234567[COLOR="#FF0000"]92[/COLOR].00 // [B]I didn't enter this value[/B] enter the number again: 2 2.00 // [B]how do I get normal "2" again?[/B] Press any key to continue . . .


Sign In
Create Account


Back to top









