Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Caculate the express:"s=s0+v0*t+(1/2)*g*t*t" (http://www.go4expert.com/forums/caculate-expressss0v0t-1-2-gtt-t23519/)

wdliming 8Oct2010 11:35

Caculate the express:"s=s0+v0*t+(1/2)*g*t*t"
 
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;
}


jimblumberg 8Oct2010 18:50

Re: Caculate the express:"s=s0+v0*t+(1/2)*g*t*t"
 
I would suggest adding parenthesis "()" surrounding the multiplication parts of your equation for clarity.

Code:

result = s0 + (v0 * t) + ( .5 * g * t * t);
Jim

wdliming 12Oct2010 17:38

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


All times are GMT +5.5. The time now is 06:23.