My project for my C++ class is to develop an application that will help me out in my programming life, and since I constantly have to use a calculator to determine the values in free fall acceleration I decided to write an application to do it for me. I was wondering if someone here could give me a quick inspection of my code to make sure it's all correct. It runs fine and there are no syntax errors what-so-ever, but I'm not 100 percent sure the math is right.
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
float startPosY = 0;
const float stopY = 0;
float Acceleration = 0, InitialAcc = 0;
float posY = 0;
int sElapsed = 1;
cout << "Please input the starting height of free fall in meters: ";
cin >> startPosY;
posY = startPosY;
cout << "Please input the acceleration of the object in m/s: ";
cin >> InitialAcc;
Acceleration = InitialAcc;
while (posY > 0)
{
posY -= Acceleration;
Acceleration += InitialAcc;
if (posY >= 0)
{
cout << "Current height: " << posY << " meters\nTime Elapsed: " << sElapsed << " seconds.\n\n";
sElapsed++;
}
else
{
posY = 0;
cout << "Current height: " << posY << " meters.\nTime Elapsed: " << sElapsed << " seconds.\n";
}
Sleep(1000);
}
cout << "\n\nThe object fell: " << startPosY << " meters in " << sElapsed << " seconds with a final acceleration of: " << Acceleration << "m/s\n";
system("pause");
}
Thanks in advance,
Jamie