Rounding a number

If anyone can offer help, I'd very much appreciated it. This is about my 3rd program, so I'm brand new and stuck.

I am writing a program for homework that uses math to determine necksize, hatsize, and shoesize. I can make that work fine, but obviously 7.9315 is not a shoesize in the real world.

I'd like to make the program round numbers so that anything that is x.0 - x.3 will display as x, anything x.31 - x.7 will show as x.5, and anything x.71 - x.99 will display as x + 1.

I have no idea how to do this.
Thanks for any help you can give...
Look
You can use
1
2
3
4
5
6
7
8
9
10
11
#include <iomanip>

using namespace std;

int main(){
  double d=1.22233322;
  //I don't remember if this counts the integer too... check it =)
  cout << setprecision(3) << d;
  return 0;
}
/*This gives you the "cut" number, for the rest... Do you need help constructing the IFs?*/
Ooooh fuck I got it now, sorry. If it's not urgent i'll write you it tomorrow: it's 4am in Italy...
HeartBallon you are wonderful.

I was able to truncate the decimals perfectly, so no one has a shoesize of 10.9735 anymore.

As for the IFs...I could use help.
Here is my thought:
I'd need to take the shoesize (pretend it is 7.24) and somehow get the program to realize that since the decimal part is < .3, the shoesize should be 7. If the shoesize was 7.45, I'd want the program to realize the shoesize should be 7.5.

So I need to do something like
if (shoesize - (shoesize without the decimal part) < .3) then shoesize = 7
Only, I've already defined shoesize as a double, and it seems in my mind I'd need to subtract the int from the double...is that even possible?
I think I've solved it! My big issue was having three conditional statements. However, using an if, and if else, and an else statement made everything work.

Woohoo!
:)
Topic archived. No new replies allowed.