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

wdliming's Avatar, Join Date: Sep 2010
Go4Expert Member
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 shabbir; 8Oct2010 at 16:35.. Reason: Code blocks
0
jimblumberg's Avatar
Ambitious contributor
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 like this
0
wdliming's Avatar, Join Date: Sep 2010
Go4Expert Member
thank you