In: Computer Science
write c++ program that takes the depth ( in kilometer) inside the earth to compute and display the temperature at the depth in degrees celsius and fahrenheit. the relevant formulas are:
celsius+ 10 x depth + 20
fahrenheit = 9/5 celsius + 23
Answer:
The given formulae in the question are wrong the actual formula to convert depth into
Celsius =10 * depth + 20
Fahrenheit= 9/5 * Celsius+ 32
Here I am providing the c++ code as per your requirements
Raw code:
#include <iostream>
//including input output streams
using namespace std;
//using namespace standard
int main()
//main
{
float depth; //declairing variable for depth of datatype as float
float cel,fahr;//declairing variable for celsius and Fahrenheit
cout<<"Please enter the depth(Kilometers):"; //prompting the user
cin>>depth; //taking the depth input
cel= 10.0*depth+20.0; //formula to convert into celsius
fahr=(9.0/5.0)*(cel)+32.0;//formula to convert to Fahrenheit
cout<<"Celsius:"<<cel<<endl;//printing the celsius degrees
cout<<"Fahrenheit:"<<fahr<<endl;//printing the Fahrenheit degrees
return 0;
}
Code in the editor:
output:
Please feel free to comment in the comment section if you have any doubts or queries
Thank you!
Note: if you want to code as per the formula you have provided, please change 12 and 13 lines in the code editor.
Hoppe this helps!