Please send questions to
st10@humboldt.edu .
#include <iostream>
using namespace std;
// Contract: void -> int
// Purpose: interactively find out how many rats there
// are, get their weights, and determine the total
// of all of their weights. Print this total weight
// in a message to the screen.
//
// Examples: if, when prompted, the user enters 4,
// then the user should be prompted to enter
// 4 rat weights; if the 4 weights entered
// are 13.3, 5, 27.1, and 15.5, then it
// should print to the screen:
// The total weight is 60.9
//
// by: Sharon M. Tuttle
// last modified: 10-28-03
int main ( )
{
// local declarations
double weight, total = 0;
int num_rats;
// how many rats are there?
cout << "how many rats are being entered? ";
cin >> num_rats;
// get each rat's weight, accumulate sum of weights
for (int i=0; i < num_rats; i++)
{
cout << "Enter the next rat weight: ";
cin >> weight;
total += weight;
}
// report the sum of all the rats' weights
cout << endl << "The total weight is " << total << endl;
return 0;
}