cs31day12 Wk 6 M

# cs31day12 Wk 6 M - ARRAYS CONTINUED....THEN STRINGS const...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ARRAYS CONTINUED....THEN STRINGS const int MAX_NUMBER_OF_SCORES = 10000; int scores[MAX_NUMBER_OF_SCORES]; int nScores = 0; double total = 0; cout &amp;lt;&amp;lt; &amp;quot;Enter the scores (negative to quit):&amp;quot; &amp;lt;&amp;lt; endl; for (;;) { int s; cin &amp;gt;&amp;gt; s; if (s &amp;lt; 0) break; if (nScores == MAX_NUMBER_OF_SCORES) { cout &amp;lt;&amp;lt; &amp;quot;I can handle only &amp;quot; &amp;lt;&amp;lt; MAX_NUMBER_OF_SCORES &amp;lt;&amp;lt; &amp;quot; scores!&amp;quot; &amp;lt;&amp;lt; endl; cout &amp;lt;&amp;lt; &amp;quot;Continuing with just the first &amp;quot; &amp;lt;&amp;lt; MAX_NUMBER_OF_SCORES &amp;lt;&amp;lt; &amp;quot; values.&amp;quot; &amp;lt;&amp;lt; endl; break; } total += s; scores[nScores] = s; nScores++; } if (nScores == 0) cout &amp;lt;&amp;lt; &amp;quot;There were no scores, so no stats&amp;quot; &amp;lt;&amp;lt; endl; else { double mean = total / nScores; cout &amp;lt;&amp;lt; &amp;quot;The mean is &amp;quot; &amp;lt;&amp;lt; mean &amp;lt;&amp;lt; endl; double sumOfSquares = 0; for (int k = 0; k &amp;lt; nScores; k++) { double diff = scores[k] - mean; sumOfSquares += diff * diff; } cout &amp;lt;&amp;lt; &amp;quot;The std. deviation is &amp;quot; &amp;lt;&amp;lt; sqrt(sumOfSquares) / nScores &amp;lt;&amp;lt; endl; } ___________________________________________________________ _______________________________ double computeMean(const int a, int n); int main() { .......
View Full Document

## This note was uploaded on 02/02/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

### Page1 / 5

cs31day12 Wk 6 M - ARRAYS CONTINUED....THEN STRINGS const...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online