Write a function that calculates the speed of sound (a) in air of a given temperature T (Fahrenheit) which is passed as parameter and returns the speed. Be sure your function does not lose the fractional part of the quotient in the formula shown. Formula to compute the speed in ft/sec:
alpha = 1086sqrt((5T+297)/(247)
#include <iostream>
#include <cmath>
using namespace std;
double CalculateSpeed(double temperature)
{
double result = 1086 * sqrt((5 * temperature + 297)/247);
return result;
}
int main()
{
double t;
cout << "Enter the value of temperature: ";
cin >> t;
cout << "The speed is " << CalculateSpeed(t) << endl;
return 0;
}
Comments
Leave a comment