Thread: Heat Equation C++

  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
    Location
    Inside my computer
    Posts
    24,654
    Those are warnings... what errors?

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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, 12:29 PM
  5. Quadratic Equation Program
    By Ambizzy in forum C Programming
    Replies: 4
    Last Post: 02-19-2002, 09:21 PM