So I had a code to begin with but still the code has math error where it doesnt
ID: 3863239 • Letter: S
Question
So I had a code to begin with but still the code has math error where it doesnt store the g as a decimal and the math logic is wrong can you please fix this?
#include <iostream>
#include<math.h>
using namespace std;
int main(){
int PE,KE,m =1 ,g =9.8 ,h = 100 ,v , deltaH = 0, TE,
clrscr();
cout<< "Enter Velocity:" << endl;
cin >> v;
PE = m * g * h;
KE = 1/2*(m*v*v);
TE = PE+KE;
cout<<"Total Energy:"<< TE<<endl;
cout<<"Potential Energy:"<< PE<<endl;
cout<<"Kinetic Energy:"<< KE<< endl;
deltaH = h - deltaH;
v = sqrt(2* g * deltaH);
cout<< "Velocity:"<<v<<endl;
return 0;
}
Explanation / Answer
PROGRAM :
#include <iostream>
#include<math.h>
using namespace std;
int main(){
float m =1 , h = 100,h1=0;
float PE=0,KE=0,g =9.81,v,TE=0;
for(h1=0;h1<=100;h1=h1+10)
{
PE = (m*g*(h-h1));
v = sqrt(2*g*h1);
KE = (0.5)*(m*v*v);
TE = PE+KE;
cout<<"HEIGHT: "<< h1;
cout<<" Total Energy: "<< TE;
cout<<" Potential Energy: "<< PE;
cout<<" Kinetic Energy: "<< KE;
cout<<" Velocity: "<<v<<endl;
cout<<"----------------------------------------------------------------------------------------------------"<<endl;
}
return 0;
}
OUTPUT;
HEIGHT: 0 Total Energy: 981 Potential Energy: 981 Kinetic Energy: 0 Velocity: 0
----------------------------------------------------------------------------------------------------
HEIGHT: 10 Total Energy: 981 Potential Energy: 882.9 Kinetic Energy: 98.1 Velocity: 14.0071
----------------------------------------------------------------------------------------------------
HEIGHT: 20 Total Energy: 981 Potential Energy: 784.8 Kinetic Energy: 196.2 Velocity: 19.8091
----------------------------------------------------------------------------------------------------
HEIGHT: 30 Total Energy: 981 Potential Energy: 686.7 Kinetic Energy: 294.3 Velocity: 24.2611
----------------------------------------------------------------------------------------------------
HEIGHT: 40 Total Energy: 981 Potential Energy: 588.6 Kinetic Energy: 392.4 Velocity: 28.0143
----------------------------------------------------------------------------------------------------
HEIGHT: 50 Total Energy: 981 Potential Energy: 490.5 Kinetic Energy: 490.5 Velocity: 31.3209
----------------------------------------------------------------------------------------------------
HEIGHT: 60 Total Energy: 981 Potential Energy: 392.4 Kinetic Energy: 588.6 Velocity: 34.3103
----------------------------------------------------------------------------------------------------
HEIGHT: 70 Total Energy: 981 Potential Energy: 294.3 Kinetic Energy: 686.7 Velocity: 37.0594
----------------------------------------------------------------------------------------------------
HEIGHT: 80 Total Energy: 981 Potential Energy: 196.2 Kinetic Energy: 784.8 Velocity: 39.6182
----------------------------------------------------------------------------------------------------
HEIGHT: 90 Total Energy: 981 Potential Energy: 98.1 Kinetic Energy: 882.9 Velocity: 42.0214
----------------------------------------------------------------------------------------------------
HEIGHT: 100 Total Energy: 981 Potential Energy: 0 Kinetic Energy: 981 Velocity: 44.2945
----------------------------------------------------------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.