demo-forloop-mean - for(int i = 1; i <= N; i++)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// Looping demo program: Computing a mean #include <iostream> // for cin, cout, endl using namespace std; const int N = 10; // how many data points int main() { double cur; // current data point double sum = 0; // sum of all data points entered // (same units as data points) double mean; // sample mean // (same units as data points)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for(int i = 1; i &lt;= N; i++) // sum the data points { cout &lt;&lt; &quot;Enter a data point: &quot;; // read next data point cin &gt;&gt; cur; sum = sum + cur; // add input to running sum } mean = sum/N; // divide by number of data points cout &lt;&lt; &quot;\nSample mean: &quot; &lt;&lt; mean; // display result return 0; }...
View Full Document

Ask a homework question - tutors are online