Created
August 1, 2018 14:54
-
-
Save Elsayegh/7e7dbe3f0108b6e1e1e69c34e19dccc3 to your computer and use it in GitHub Desktop.
C++ Calculate Kinetic Energy (C++ Functions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Write a function named kineticEnergy that accepts an object's mass (in kg) and velocity (in m/s) as arguments. | |
| The function should return the amount of kinetic energy that the object has. | |
| Demonstrate the function by calling it in a program that asks the user to enter values for mass and velocity. | |
| KE = 1/2 * m * v(to the power of 2) | |
| */ | |
| #include <iostream> | |
| #include <conio.h> | |
| #include <math.h> | |
| using namespace std; | |
| double kineticEnergy(int m, int v); | |
| int main() { | |
| double ke = 0; int m = 0; | |
| int v = 0; | |
| cout << "Please enter mass in kg: "; | |
| cin >> m; | |
| cout << "Please enter veloicty in meters per second: "; | |
| cin >> v; | |
| ke = kineticEnergy(m, v); | |
| cout << "Keinetic Energy of this object is: " << ke << endl; | |
| _getch(); | |
| } | |
| double kineticEnergy(int m, int v) { | |
| return (0.5 * m) * (pow(v, 2)); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment