Heat Equation C++

This is a discussion on Heat Equation C++ within the C++ Programming forums, part of the General Programming Boards category; Hello, Everyone: I am trying to develop a C++ program using the heat equation. However, I am getting errors from ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    30

    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
    Last edited by mikeprogram; 11-10-2007 at 10:02 PM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,888
    Those are warnings... what errors?

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    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.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    30
    Thank you for your help, brewbuck, you were right.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 11-04-2006, 04:06 AM
  2. IDEA: Equation solver
    By Magos in forum Contests Board
    Replies: 2
    Last Post: 01-07-2003, 11:46 AM
  3. Equation solving
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-24-2002, 02:13 PM
  4. why different answers for this equation
    By james_nkh in forum C Programming
    Replies: 2
    Last Post: 05-21-2002, 01:29 PM
  5. Quadratic Equation Program
    By Ambizzy in forum C Programming
    Replies: 4
    Last Post: 02-19-2002, 09:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21