/* * File: sum.cpp * Author: Robert I. Pitts * Last Modified: January 27, 2000 * Topic: UNIX Basics * * Slightly modified by Drue Coles on July 25, 2003 to * conform with the latest version of gnu g++. * * ---------------------------------------------------------------- * * Usage: * ===== * The user first enters the how many numbers need to be * averaged and hits . Then, the user enters each * of the numbers on a separate line. */ #include using namespace std; int main() { int howmany; // How many values to sum. float sum = 0.0; // The running sum. // Ask how many numbers to read. cout << "Enter how many numbers I will sum: "; cin >> howmany; for (int i = 0; i < howmany; i++) { float value; // The current value. cout << "Enter number: "; cin >> value; // Read the ith number. sum += value; // Increment the sum. } cout << "The sum is: << sum << endl; cout << "Thank you for using the summer!" << endl; return 0; // 0 means program exited successfully. }