Caculate the express:"s=s0+v0*t+(1/2)*g*t*t"

Discussion in 'C++' started by wdliming, Oct 8, 2010.

  1. wdliming

    wdliming New Member

    Joined:
    Sep 26, 2010
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Description :Caculate the express:
    "s=s0+v0*t+(1/2)*g*t*t"
    ***************************************/
    Code:
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    int main()
    {
        double s0 = 0;
        double v0 = 0;
        double g = 0;
        double t = 0;
        double result=0;
        cout << "Please input three numbers:\
        s0 v0 g t" << endl;
        cin >> s0 >> v0 >> g >> t;
        //cout << s0 <<"\v"<< v0 <<"\v"<< g <<"\v"<< t << endl;
        /*\v 竖向跳格*/
        result = s0 + v0 * t + 0.5 * g * t * t;
    
        cout << "result = "<<s0<<"+"<<v0<<"*t"<<"+"
        <<"0.5*"<<g<<"*t^2"<<" = "<<result<<endl;
    
        cout << "Hello world!" << endl;
        return 0;
    }
     
    Last edited by a moderator: Oct 8, 2010
  2. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    I would suggest adding parenthesis "()" surrounding the multiplication parts of your equation for clarity.

    Code:
     result = s0 + (v0 * t) + ( .5 * g * t * t); 
    Jim
     
    shabbir likes this.
  3. wdliming

    wdliming New Member

    Joined:
    Sep 26, 2010
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice