Write a program that calculates the energy needed to heat water from an initial temperature to a final temperature. Your program should prompt the user to enter the amount of water in kilograms and the initial and final temperatures of the water.
heat water from an initial temperature to a final temperature. Your program should
prompt the user to enter the amount of water in kilograms and the initial and final
temperatures of the water. The formula to compute the energy is
Q = M * (finalTemperature – initialTemperature) * 4184
where M is the weight of water in kilograms, temperatures are in degrees Celsius, and
energy Q is measured in joules.
#Beginner
In gcc c++ compiler using namespace std;
#include<iostream>
using namespace std;
int main()
{
float M,finalTemperature,initialTemperature;
cout<<"Enter te amount of water in kilograms :";
cin>>M;
cout<<"Enter the initial temperature :";
cin>>initialTemperature;
cout<<"Enter te finalTemperature :";
cin>>finalTemperature;
float Q=M*(finalTemperature-initialTemperature)*4184;
cout<<"The energy needed is "<<Q<<endl;
return 0;
}
Output
Enter te amount of water in kilograms :4
Enter the initial temperature :30
Enter te finalTemperature :100
The energy needed is 1.17152e+06
[Program finished]
Comments
Post a Comment
Any doubt about programming or questions