Repository navigation
Expand file tree
/
Copy path3_function1.cpp
More file actions
42 lines (31 loc) · 1.56 KB
/
Copy path3_function1.cpp
File metadata and controls
42 lines (31 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* calculating the Reynolds number using a "void" function
written by Tariq Ridwan: 👉 https://tariqridwan.github.io/
Universitat Politècnica de Catalunya, Barcelona */
#include<iostream>
#include<string>
// #include<cmath>
// using namespace std;
void Reynolds(double density, double velocity, double viscosity, double characteristic_length); // Prototype: Returns void instead of double
int main()
{
double rho, U, mu, D;
std::string write_intro = "Calculating Reynolds number\n";
std::cout << write_intro;
std::cout << "What is the velocity in (m/s)?" << std::endl;
std::cin >> U;
std::cout << "What is density in (kg/m³)?\n";
std::cin >> rho;
std::cout << "What is the dynamic viscosity?" << std::endl;
std::cin >> mu;
std::cout << "What is the characteristic length (m)?" << std::endl;
std::cin >> D;
// double Re = (rho*U*D)/mu;
// std::cout << "The Reynolds number is: " << Re << std::endl; // calculating directly like this is not a good practice, instead we can use a function to calculate it as shown below. This is a better practice in programming to use functions for calculations.
std::cout << "So the Reynolds number is:" << std::endl;
Reynolds(rho,U,mu,D); // calling the function for calculation instead of calculating directly like: double Re = (rho*U*D)/mu; (as shown above) which is not a good practice.
return 0;
}
void Reynolds(double density, double velocity, double viscosity, double characteristic_length)
{
std::cout << density*velocity*characteristic_length/viscosity << std::endl;
}