### -1.#IND error

Hey there, I have some coding experience but I still seem to get the occasional confusing error. For the most part I believe I have this code written correctly until it displays the output for Q and TC. It displays -1.#IND in the command prompt. Can someone point me towards where I might have an error?

#include <iostream>
#include <cmath>
using namespace std;

int main()
{

float P, C, h, D, Q, TC;

cout << "What is the annual production rate? " << endl;
cin >> P;
cout << "What is the fixed cost incurred for each production phase? " << endl;
cin >> C;
cout << "What is the inventory holding cost per item? " << endl;
cin >> h;
cout << "What is the annual demand for the item? " << endl;
cin >> D;

Q = sqrt((2*C*D)/(h*(1-D/P)));
TC = ( ( C * D ) / Q ) + ( ( h * ( 1 - D / P ) * Q ) / 2 );

cout << "The optimal production quantity is " << Q << endl;
cout << "The annual production cost is " << TC << endl;

return 0;
}
An IND error in visual studio basically means NaN (Not a Number).

This is either happening because you are dividing by 0 or taking the square root of a negative number (probably the second one in this example). Look at your formula carefully and see why this might be happening.

Also in future please use [ Code] [ /Code] tags to make things easier to read.
Topic archived. No new replies allowed.