编写程序,计算将水从初始温度加热到最终温度所需的能量。程序应该提示用户输入水的重量(以千克为单位),以及水的初始温度和最终温度。计算能量的公式是:
Q = M ×(最终温度 – 初始温度)× 4184
这里的M是以千克为单位的水的重量,温度以摄氏度为单位,而能量Q以焦耳为单位。
#include <QCoreApplication>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int M,Start,End;
float Q;
cout<<"Please Input WaterWeight: ";
cin>>M;
cout<<"Please Input StartTem: ";
cin>>Start;
cout<<"Please Input EndTem: ";
cin>>End;
if(Start-End>0)
{
return 0;
}
else
{
Q=M*(End-Start)*4184;
}
cout<<"Enger = "<<Q<<endl;
return 0;
}