Responsive Ad Area

Share This Post

test

Program that accepts input for falling time the returns distance in meters and passes values to 1 through 10 as well

I am trying to design a very simple function named fallingDistance that accepts an objects falling time in seconds and returns the distance in meters. Then I need a program that demonstrates the function by calling it in a loop that passes the values 1 through 10 as arguments and displays the values.

Please I need my code to be super simple and nothing past my beginning level of programming.

I know my issue is with time as the first function accepts and holds the value that the user input. In my second function I wish to have time reset to 0 and go to 10 showing the appropriate falling distance as referenced in the function. I wish for it to output all distances for a falling distance of 1 to 10.
How do I reset the second function to start at 1 and go to 10 utilizing the first function?

#include <iostream>
#include <cmath>
using namespace std;

//Write a function that accepts falling time in seconds.
double fallingDistance(double time)
{
    double distance;
    distance = (pow(time, 2)) * 9.8 * 0.5; // Formula for distance

    //Accept user input.
    cout << "Please enter the objects falling time in seconds as a double: " 
        << endl;
    cin >> time;  // capture input

    // Return distance in meters.
    cout << "An object that has been falling for " << time << " seconds, has 
        fallen " << distance << " meters." << endl;

    return distance;
}

int main () //How do I break the previously entered time to start over from 1 
then increment???
{
   int t = 0;
   t = t + 1;
   t++;

   // Loop that displays and passes values 1-10.
   while( t < 10)
   {
       double time, distance;
       time = 1.0;
       time = time + 1;
       time++;

        //Program that calls previous function into loop.
        distance = fallingDistance(time);
        cout << "An object that has been falling for " << t << " seconds, has 
   }
return 0;
}


Program that accepts input for falling time the returns distance in meters and passes values to 1 through 10 as well
Program that accepts input for falling time the returns distance in meters and passes values to 1 through 10 as well
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar