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; }
I would suggest adding parenthesis "()" surrounding the multiplication parts of your equation for clarity. Code: result = s0 + (v0 * t) + ( .5 * g * t * t); Jim