How to keep answers from rounding?

This is my code, everything is working but my assignment wants for inputs 10, 56, and 33 to have a wait time of 1.99 before the balloon hits the ground. My outputs round it up to 2.00, and it considers this incorrect. How can I change it? Thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
int main(){
  float velocity = 0;
  float timeElapsed = 0;
  float distance;
  float height;
  float walkSpeed;
  cout <<"How far away is your friend(feet)?: ";
  cin >> distance;
  cout <<"How fast is your friend walking(feet/sec)?: ";
  cin >> walkSpeed;
  cout <<"How high are you dropping the balloon from(feet)?: ";
  cin >> height;
  while(height > 0){
    timeElapsed += 0.001;
    height -= velocity/1000.0;
    velocity += 0.032 - velocity * 0.0012;
  }
  float timeToWalk = distance / walkSpeed;
  float waitTime = timeToWalk - timeElapsed;
  if(waitTime > 0.0){
    printf ("\nIt will take %.2f seconds for them to reach the balloon point.", timeToWalk);
    printf ("\nIt will take %.2f seconds for your balloon to travel to the ground.", timeElapsed);
    printf ("\nIf you wait %.2f seconds, you will hit them.\n", waitTime);
  }else{
    printf ("\nIt will take %.2f seconds for them to reach the balloon point.", timeToWalk);
    printf ("\nIt will take %.2f seconds for your balloon to travel to the ground.", timeElapsed);
    cout << "\nIt is too late to drop your balloon.\n";
  }
  }
Change the types of all the variables from float to double.
In general, use double as the default floating point type.
I don't think there are any guarantees here. It looks like the answer for those inputs is exactly 1.995. But because of the limited precision of floating-point values, the calculated result could be either a little bit over (1.995037) or a little bit under (1.994999) and so rounding up to 2.00 or down to 1.99 could both be considered correct.

You could try changing from type float to double throughout which might happen to give the result you are supposed to have.
That did the trick! I'll keep that in mind in the future. Thanks.
Topic archived. No new replies allowed.