Here is my code again, I fixed the first problem but now when I echo the initial height it shows a number like 0.94 which is what the update statement is producing. How do I set it so that it echos the intial height that the user inputs, while still working the way it does?
Code:
// File: Golf_Ball.cpp
// Author: ----------------
// Class: ITCS 1214 TR 5pm
// Date: 03/20/08
// Purpose: To determine number of bounces a golf ball
// will make given type of surface and height from which
// it is dropped.
#include <iostream>
using namespace std;
int main ()
{
string surface_name = " "; // Name of each type of surface
float bounce_counter = 0.0,
height; // Height given by user
char surface_code; // Code for each type of surface, C, W, or R
// Prompt for and read in height in feet
cout << "Enter the drop height (in feet): ";
cin >> height;
// Prompt for and read in type of surface
cout << "Enter the type of surface (C, W or R): ";
cin >> surface_code;
// Test for which type of surface entered and how many bounces will occur
if (surface_code == 'C')
{
while (height > 1)
{
height = height * 0.85;
bounce_counter = bounce_counter + 1;
surface_name = "concrete";
}
}
else
{
if (surface_code == 'W')
{
while (height > 1)
{
height = height * 0.60;
bounce_counter = bounce_counter + 1;
surface_name = "wooden";
}
}
else
{
while (height > 1)
{
height = height * 0.20;
bounce_counter = bounce_counter + 1;
surface_name = "rug";
}
}
}
// Echo surface type and height, then display number of bounces
cout << "On a " << surface_name << " floor from " << height;
cout << " feet the ball will bounce " << bounce_counter << " times.\n";
return 0;
}
here is the output by the way,
Enter the drop height (in feet): 15
Enter the type of surface (C, W or R): C
On a concrete floor from 0.946701 feet the ball will bounce 17 times.
Everything is right, except the 0.94 should just be 15 again.