-
decimal place help
I am new at programming using C++. I am trying to write a program where ouput needs to be formatted to fit certain decimal place criteria. I am using Visual Basic C++. The folowing is just some of the program I wrote:
cout << fixed << showpoint;
then some equations, then,
cout << setprecision(0) << htInches << " inches" << endl;
cout << setprecision(2) << htMeters << " meters" <<endl;
cout << setprecision(0) << htCentimeters<< " centimeters" << endl;
I am racking my brain trying to get this to work. I have been all through the book also. No help at all. Any help I can get would be appreciated. Thank you in advance.
-
Desparate for help
Any suggestions would be great. Anything really. Thank you.
-
hmm are you using visual basic or visual c++...hehe..thats my first question..but it seems like you are using visual c++
here is code:
Code:
#include <iostream>
using namespace std;
int main()
{
float x = 1.2345f;
cout.setf(ios::fixed);
cout.precision(3);
cout << x << endl;
return 0;
}
well it should output only 1.235 since precision is set to 3 it will only out 3 digits after the decimal which is the 4 but it's rounding it up to a 5 because of the 5. hope that helps
-
I got it
I got it figured out. Thank you