• Log in or sign up for an account here: https://www.sythe.org/login

A little help with a project please...

Chase

Whore

Retired Global Moderator
Joined
Mar 8, 2006
Sythe Gold
11
Messages
1,858
Age
33
Create a program that asks the number of floors in a building and the height of a floor.
Compute the time it would take for a water balloon dropped from the top of the building
to hit the ground and what the speed the balloon will have just before it hits. Use the
following equations:
acceleration = (velocity_final - velocity_initial) / time
distance = 1/2 (velocity_final - velocity_initial) * time
acceleration is due to gravity alone (9.8 m/s^2)
distance is the height the balloon is dropped
velocity_initial is 0 m/s (the balloon is gently released, not thrown)
I know how to do the language itself, just a little problem with the equations. What are the integer/floats i should specify, and how should i go about doing the equations? I'm stuck, as this is really stumping my mind about how to do it.
 
I happen to be a physicist by profession. If you have any questions, then feel free to send a PM my way.

Code:
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
     //Variables
    double acceleration = 9.8;
    double velocity_final = 0;
    double velocity_initial = 0;
    double distance = 0;
    double height_of_floor = 0;
    double time = 0;
    int number_of_floors = 0;

    //Initialize data
    cout << "How many floors in the building?" << endl;
    cin >> number_of_floors;

    cout << "What is the height of a floor?" << endl;
    cin >> height_of_floor;


    //Any item with no air resistance will drop at a constant 9.8 meters per second times second.
    //So if we know the distance of the fall then we can compute the time by setting both equations
    //equal to each-other as we already know the acceleration!

    //Distance is number_of_floors times height_of_floor
    //acceleration = (velocity_final - 0) / time so that we get:
    //acceleration = velocity_final / time which means that:
    //velocity_final = acceleration*time
    distance = number_of_floors*height_of_floor;
    time = sqrtf(2*distance/acceleration);
    velocity_final = acceleration*time;

    cout << "The balloon takes " << time << " s to hit the floor." << endl;
    cout << "The final velocity of the balloon is " << velocity_final << " m/s." << endl;



    return 0;
}
 
imag0100ot.jpg

imag0101eo.jpg
 
Thanks so much, I got it down. By looking at your source I figured out what I had to do and used printf to do it instead. Thank you, you got me an A on the project, haha. If I have any problems, you'll be the first I come too.
 
Runescape Gamblingrunescape gambling
Back
Top