{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

solutions13 - sum = 0 count = 0 cout<<"Enter first...

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

View Full Document Right Arrow Icon
CSCI-1100 Computer Science I Rensselaer Polytechnic Institute Spring 2004 Studio 13 -- Solutions 2. #include <iostream> using namespace std; int main () //PURPOSE: compute average of list of numbers //PRECONDITION: none //POSTCONDITION: return 0 if successful { int num; // number from list int count; // count of numbers in list int sum; // sum of numbers in list float avg; // average of numbers in list // read, sum and count numbers
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: sum = 0; count = 0; cout << "Enter first number (negative to stop): "; cin >> num; while (num >= 0) { sum = sum + num; count = count + 1; cout << "Enter next number (negative to stop): "; cin >> num; } // compute and display average avg = (float) sum / (float) count; cout << endl << endl; cout << "The average is " << avg << endl; return 0; }...
View Full Document

{[ snackBarMessage ]}