//Charlotte Davies-Kiernan              CS1A             Chapter 6 P. 370 #6
//
/*****************************************************************************
 * 
 * Compute Kinetic Energy
 * ___________________________________________________________________________
 * This program will compute the kinetic energy of an object using the mass
 * and velocity entered
 * 
 * Formula used:
 * kinetic energy = mass * velocity * velocity * 0.5
 * ___________________________________________________________________________
 * Input
 *   mass       //Mass of the object
 *   velocity   //Velocity of the object
 * Output
 *   kE         //Kinetic Energy of the object
 *****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
 
//Function Prototype
float kineticEnergy(float mass, float velocity);
 
int main() {
//Data Dictionary
    float mass;        //INPUT - Mass of the object
    float velocity;    //INPUT - Velocity of the object
    float kE;          //OUPUT - Kinetic Energy of the object
cout << "Kinetic Energy Calculator: " << endl;
//Get User's Inputs
cout << "Enter the object's mass (in kilograms): " << endl;
cin >> mass;
//Input Validation
while (mass < 0){
	cout << "Mass cannot be negative. Please enter a positive value: " << endl;
	cin >> mass;
}
cout << "Enter the object's velocity (in meters per second): " << endl;
cin >> velocity;
//Input Validation
while (velocity < 0){
	cout << "Velocity cannot be negative. Please enter a positive value: " << endl;
	cin >> velocity;
}
//Calculate Kinetic Energy
kE = kineticEnergy(mass, velocity);
 
//Display Result
cout << fixed << setprecision(2);
cout << "The object's kinetic energy is " << kE << " joules" << endl;
	return 0;
}
//Kinetic Energy Function
float kineticEnergy(float mass, float velocity){
	return mass * velocity * velocity * 0.5;
}