C++ programming:
Write a program that asks the user to enter a value of power in Watts. The program performs units conversion (if necessary) and displays the power per the following prescription:
If power is less than 1 W, display in calories/min
If 1W<=P<10W, display in W
If 10W<=P<1000W, display in BTU/hr
If 1000W <= P < 10,000W, display in KW
If 10,000W<=P<100,000W, display in Kcal/sec
If 100,000W <=P<1,000,000W, display in BTU/sec
If P>=1,000,000W, display in MW
Units conversion: use 1 BTU = 252 cal = 1.055 kJ (note W=J/sec)
Your outputs must be descriptive -- do not output only numbers.
#include <iostream>
using namespace std;
int main()
{
float p=0;
cout << "enter a value of power in Watts:";
cin>>p;
if(p<1)
cout<<(p*252*60)/(1.055*1000) <<"calories/min";
else if(p>=1 && p<10)
cout<<p<<"W";
else if(p>=10 && p<1000)
cout<<(p*60*60)/(1.055*1000)<<"BTU/hr";
else if(p>=1000 && p<10000)
cout<<(p/1000) <<"KW";
else if(p>=10000 && p<100000)
cout<< (p*252)/(1.055*1000*1000) <<"Kcal/sec";
else if(p>=100000 && p<1000000)
cout<<p/(1.055*1000) <<"BTU/sec";
else if(p>=1000000)
cout<< p/1000000 <<"MW";
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.