I am using following C++ code to enter a value of X which is used to print out variable CDF. This C++ code is expected to give very similar value we get from NORMDIST function in excel. However I get following error in debugger with out getting any output in executable file. Can any body help please?

'#include<iostream>
 #include<cmath>
 using namespace std;
 const double pi = 4.0*atan(1.0);
 int main()
 {
 const double a1 = 0.319381530, a2 = -0.356563782, a3 = 1.781477937, 
 a4 = -1.821255978, a5 = 1.330274429;
 double X = 0, x = 0; double k = 0;
 double N, CDF, n;
 cout << "Enter the value of the random variable X" << endl;
 cin >> X;
 x = fabs(X);
 k = 1 / (1 + 0.2316419*x);
 n = (1 / sqrt(2 * pi))*exp(-0.5*x*x);
 N = 1 - n*(a1*k + a2*k*k + a3*pow(k, 3) + a4*pow(k, 4) + a5*pow(k, 5));
 CDF = N;
 if (X < 0)
 CDF = 1 - N;
 cout << CDF << endl;
 return 0;
 }

I checked CDF1.exe for output for example for X= 0.7693 as input, I am expecting 0.7791 but I don't see any output in CDF1.exe and I just see below in debugger. Can anybody help in trouble shoot please?

'CDF1.exe' (Win32): Loaded 'C:\Users\kdatta\Documents\CQF\C++\CDF1 Debug\CDF1.exe'. Symbols loaded.
'CDF1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'CDF1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'CDF1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'CDF1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Cannot find or open the PDB file.
'CDF1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Cannot find or open the PDB file.
The thread 0x4fc0 has exited with code -1073741749 (0xc000004b).
The program '[11216] CDF1.exe' has exited with code -1073741510 (0xc000013a).

Flush the input stream after you get the value of X.
After outputting the value of CDF, your program needs to pause so that CDF can be read.
Format your code. That way the code will be far more readable and errors will be more obvious.

I used following to pause the code. It worked. It seems I dont have to use cin.clear() to flush input stream. Thanks for feedback,

 '#ifdef _DEBUG
    system("pause");
    #endif'
This article has been dead for over six months. Start a new discussion instead.