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

Info iconThis 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
Background 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

This homework help was uploaded on 04/16/2008 for the course CSCI 1100 taught by Professor Hardwick during the Fall '08 term at Rensselaer Polytechnic Institute.

Ask a homework question - tutors are online