Skip to content

Instantly share code, notes, and snippets.

@kdmkdmkdm
Created September 20, 2013 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdmkdmkdm/6632984 to your computer and use it in GitHub Desktop.
Save kdmkdmkdm/6632984 to your computer and use it in GitHub Desktop.
average
// Qaverage.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int numToAverage = 0;
float sum = 0.0f;
float avg = 0.0f;
cout << "Enter the number of values to average: ";
cin >> numToAverage;
float average[numToAverage];
for (int i = 0; i > (numToAverage - 1); ++i)
{
cout << "[" << i << "] = ";
cin >> average[i];
sum += average[i];
}
avg = sum / numToAverage;
cout << "Average = " << avg << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment