Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculation issue in C++
    text
    copied!<p>So in this program i am trying to print out the standard deviation of a set of numbers the user enters in. The formula to calculate standard deviation is correct (or as correct as it needs to be) so that is not the problem, but when i run the program everything goes well until the console prints out the results. It prints that totalStandardDeviation = nan</p> <p>what exactly does than mean? is nan the same as nil? has it lost the value somehow and not been able to find it? thanks for any help you may provide.</p> <pre><code>#include &lt;iostream&gt; #include &lt;cmath&gt; using namespace std; double returnStandardDeviation(double x, int counter); double total; int userInput = 1; int counter = 0; double x; double x1; double x2; double standardDeviation; double totalStandardDeviation; int main(int argc, const char * argv[]) { cout &lt;&lt; "Please enter a list of numbers. When done enter the number 0 \n"; cin &gt;&gt; userInput; while (userInput != 0) // As long as the user does not enter 0, program accepts more data { counter++; x = userInput; returnStandardDeviation( x, counter); // send perameters to function cout &lt;&lt; "Please enter next number \n"; cin &gt;&gt; userInput; } cout &lt;&lt; "The standard deviation of your " &lt;&lt; counter &lt;&lt; " numbers is : " &lt;&lt; returnStandardDeviation(x, counter); return 0; } double returnStandardDeviation(double x, int counter) { x1 += pow(x,2); x2 += x; totalStandardDeviation = 0; totalStandardDeviation += (sqrt(counter * x1 - pow(x2,2))) / (counter * (counter - 1)); return totalStandardDeviation; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload