notes-repetition2-problemsoln - while(count <...

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

View Full Document Right Arrow Icon
Solution (Revised) double inputData; // holds data point currently being processed double sum; // sum of all data points entered thus far int count; // how many data points we've collected cout << "Enter a number: "; cin >> inputData; sum = inputData; // initialize sum based on first data point count = 1; // start at 1 since a point has already been entered
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: while(count &lt; 20) // process data points { cout &lt;&lt; &quot;Enter a number: &quot;; // get more data cin &gt;&gt; inputData; sum = sum + inputData; // add point to running sum count++; // update our count (the update step) } cout &lt;&lt; &quot;The sum of the inputs is &quot; &lt;&lt; sum &lt;&lt; endl; // If we wanted to use count for anything down here, we would need &quot;count--;&quot;...
View Full Document

This document was uploaded on 02/10/2011.

Ask a homework question - tutors are online