﻿ For Loop Example
```//---------------------------------------------------------
// Filename: ForLoopDemo.cpp
//
// Purpose: Find the average of a list of values. The
// values are entered by the user.
//
// This program was written to illustrate a for loop.
//
// D. Searls
// Asbury College
// Sep 2006
//---------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int numValues; // Number of values
int count;     // Number of values processed so far
double x;      // A single value from list
double sum;    // Sum of values
double avg;    // The arithmetic average

// Get number of scores

cout << "Enter the number of values in the list: ";
cin >> numValues;
cout << endl;

// Initialize sum and counter

sum = 0.0;

// Read scores, maintaining a running total and counter

for (count = 0; count < numValues; count++)
{
cout << "Enter score " << count + 1 << ": ";
cin >> x;
sum = sum + x;
}
cout << endl;

// Calculate average

if (numValues > 0)
{
avg = sum/(double)numValues;
}

// Display results

if (numValues > 0)
{
cout << "Number of scores read: " << numValues << endl;
cout << "Sum of scores: " << sum << endl;
cout << fixed << setprecision(2) ;
cout << "Average score: " << avg;
}
else
{
cout << "The list contained no scores.";
}
cout << endl << endl;
return 0;
}```