-
Heat Equation C++
Hello, Everyone:
I am trying to develop a C++ program using the heat equation. However, I am getting errors from the program. Here is the program: I get the following error messages:
Code:
heateq.cpp: In function `int main(int, char **)':
heateq.cpp:14: warning: initialization to `int' from `double'
heateq.cpp:15: warning: initialization to `int' from `double'
I need help in figuring out what I did wrong. Any suggestions? I will greatly appreciate any comments or suggestions.
mp
-
Those are warnings... what errors?
-
length_x and dx are both double variables. Their ratio is also a double. The compiler is warning you that you are taking this double value and using it to initialize an integer variable. To eliminate the warning, explicitly cast the value:
Code:
int nx = static_cast<int>(length_x / dx);
Note the integer truncation. Depending on your algorithm this might not be what you want.
-
Thank you for your help, brewbuck, you were right.