cs31day12 Wk 6 M

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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
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 << "Enter the scores (negative to quit):" << endl; for (;;) { int s; cin >> s; if (s < 0) break; if (nScores == MAX_NUMBER_OF_SCORES) { cout << "I can handle only " << MAX_NUMBER_OF_SCORES << " scores!" << endl; cout << "Continuing with just the first " << MAX_NUMBER_OF_SCORES << " values." << endl; break; } total += s; scores[nScores] = s; nScores++; } if (nScores == 0) cout << "There were no scores, so no stats" << endl; else { double mean = total / nScores; cout << "The mean is " << mean << endl; double sumOfSquares = 0; for (int k = 0; k < nScores; k++) { double diff = scores[k] - mean; sumOfSquares += diff * diff; } cout << "The std. deviation is " << sqrt(sumOfSquares) / nScores << 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 Right Arrow Icon
Ask a homework question - tutors are online