Hey y’all. Im not really too active here anymore but I’m starting university for computer science and i figured id post my progress with programming and all that I will be posting these once every week or so.
Anywhoo, this program calculates the distance an object falls given the time in seconds by the user.
// CS 1511
// Project 1
#include <iostream>
using namespace std;
int main()
{
// Variable Declarations
int time, distance;
// Inputs
cout << "This program will calculate the distance of an object in freefall. Please enter the time of the drop in seconds:";
cin >> time;
// Calculations
distance = time * time * 32 / 2;
// Output & End of program
cout << distance << " units
";
cout << "The program is now over. Thank you.
";
return 0;
}
Thanks i eat food. However, my compiler gave me error messages… I believe its because I’m logged into a Unix server run by my uni that is not running any of the latest c++ updates
This should be how your code should look with his suggestion.
#include <iostream>
using std::cout;
using std::cin;
int main()
{
// Variable Declarations
int time, distance;
// Inputs
cout << "This program will calculate the distance of an object in freefall. Please enter the time of the drop in seconds:";
cin >> time;
// Calculations
distance = time * time * 32 / 2;
// Output & End of program
cout << distance << " units
";
cout << "The program is now over. Thank you.
";
return 0;
}
If you’ve already discussed scope, then you should understand that you can also call these locally which would be a better alternative to get used to before you start larger scaled programs in order to avoid polluting your project’s namespace.
#include <iostream>
int main()
{
using std::cout;
using std::cin;
// Variable Declarations
int time, distance;
// Inputs
cout << "This program will calculate the distance of an object in freefall. Please enter the time of the drop in seconds:";
cin >> time;
// Calculations
distance = time * time * 32 / 2;
// Output & End of program
cout << distance << " units
";
cout << "The program is now over. Thank you.
";
return 0;
}