# rounding

• 06-24-2006
limitmaster
rounding
Im making a program that will convert centimeters(float) to feet(int) and inches(float)...here's the code;

Code:

```#include <iostream> #include <conio.h> using namespace std;   int main() { float cen, inch; int feet; cout << "input centimeter to be converted to feet and inches: " << endl; cin>> cen; cout << cen << " is " << (feet=0.03280839895*cen) << " feet and " << (inch=0.3937007874*cen) << " inches\n"; getch(); }```
the problem is how can i round the float numbers in one decimal places for example the user will input 3333 for the centimeters and the output will be like this....
333.3 is 10 feet and 131.2 inches
i don't know how to do it if the user input 3333 the program will read it as 333.3 and will convert it to feet and inches.... I know how to do it using C code but in C++ dont know how....anyone there any ideas... really need help
• 06-24-2006
Cactus_Hugger
I'm not understanding your question. Translate it to English, and post back.

The only problem I can see it that inches > 12, perhaps not what you want? If not, take inches and subtract feet*12.
• 06-24-2006
limitmaster
okey....here it goes im making a program that will convert centimeters to feet and inches...
for example the user will input 3333 for centimeters the program will convert it to feet and inches.....THE PROGRAM MUST READ 3333 AS 333.3..... and 333.3 will be used for the convertion.
NOW HERE's THE PROBLEM HOW CAN I ONLY HAVE ONE DECIMAL PLACE WHEN THE PROGRAM CONVERT CENTIMETER TO INCHES NO PROBLEM FOR THE FEET IT'S JUST THE INCHES HOW CAN I HAVE ONE DECIMAL PLACE ONLY...
another example..
centimeter to inches = 131.22 to 131.2 <-------- how is that...///????
• 06-24-2006
Mario F.
Nervous already? All Caps is ugly. It looks like you are shouting. Are you shouting?

It is still badly explained. What do you mean the user enters 3333 and it gets converted to 333.3? This is not the same number. You mean if he inserts anything higher than 3 digits, the extra digits become decimal places? Or maybe you mean it becomes 3333.0?

And exactly where do you want to do this conversion? That is badly explained too. Before doing the calculation? Or after when outputing the number to the screen?
• 06-24-2006
limitmaster
Nope im not shouting....sorry for the CAPS
if the input value value is 3333 the output should be 333.3 centimeters is 10 feet 131.2 inches
not 333.3 centimeters is 10 feet 131.22 inches there are 2 decimal places in inches i want it only one....thanks
• 06-24-2006
Mario F.
Err... ok, I think.

use the setprecision manipulator.

Code:

```#include <iostream> #include <iomanip> std::cout << std::setprecision (5) << 2348.4356 << std::endl; // outputs 2348.4```
• 06-24-2006
whiteflags
Code:

```#include <iomanip> // magic numbers ought to be avoided when they can be cout << fixed << setprecision(5) << cen << " is " << (feet=0.03280839895*cen) <<         " feet and " << (inch=0.3937007874*cen) << " inches\n";```
edit: foiled by Mario! -plays as Wario- :p
• 06-24-2006
Mario F.