An Example of a for Loop
#include <iostream.h>
/************************************************************
File: for_loop.C
This program demonstrates the use of a for loop
************************************************************/
int main()
{
int num, count, sum;
cout << "Enter integer values, ^d to quit: ";
for ( count=0, sum=0; cin >> num; count++, sum += num); //LOOP
float average = float(sum)/count;
cout << "You entered " << count << " numbers" << endl;
cout << "The average value is: " << average << endl;
return(0);
}
Back to Previous Page
Document:
Local Date:
Last Modified On: