• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

C++ \\ Newton's Laws of Motion

SuSa

Banned via Administration
Joined
Jul 20, 2008
Messages
11,508
Location
planking while watching anime with Fino

Somewhere on:
http://www.uow.edu.au/~nabg/ABC/C6.pdf

"Write a program that uses Newton's laws of motion to calculate the speed and the
distance travelled by an object undergoing uniform acceleration. The program is to take
as input the mass, and initial velocity of an object, and the constant force applied and
time period to be considered. The program is to calculate the acceleration and then use
this value to calculate the distance travelled and final velocity at the end of the specified
time period."

Program I ended up writing:
http://web-dev.pastebin.com/d27400bc2



Did I do it right? >.< I don't think I needed to include math.h

EDIT:
I did it the hard way. Turns out the answer was:
Code:
double s, u, a, t;
cout << "Enter initial velocity, acceleration, and time : ";
cin >> u >> a >> t;
s = u*t + 0.5*a*t*t;
cout << "Distance travelled " << s << endl;
 

Oskurito

Smash Lord
Joined
Jan 28, 2006
Messages
1,948
Location
Hell
lol thats pretty basic. The only thing you need to know, is newton's laws of motion. The rest is just an easy use of the standard c++ iostream library with cout and cin functions.

I like the old way tho. printf and scanf makes more much sense for me.

EDIT: if that's all of your code that is inside the main function, I say nope, you don't need the math header, just iostream.
 

SuSa

Banned via Administration
Joined
Jul 20, 2008
Messages
11,508
Location
planking while watching anime with Fino
I'm been coding in c++ for all of a matter of...... that day. <_< I then went on vacation and just got back.

Thought so. Didn't know the math header. :p

/next little program will be using a function. wee... simple stuff still but I need to learn it
 
Top Bottom