Created
April 22, 2012 07:48
-
-
Save kdmkdmkdm/2462552 to your computer and use it in GitHub Desktop.
averageWithTheHelpOfRedditCPlusPlus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// averageWithTheHelpOfReddit | |
#include "stdafx.h" | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
// Declare. | |
int numberOfInputs = 0; | |
float valueOfCurrentInput = 0.0f; | |
float sum = 0.0f; | |
float avg = 0.0f; | |
cout << "Enter the number of values to average: "; | |
cin >> numberOfInputs; | |
// Find sum. | |
for(float valueOfCurrentInput = 0.0f; valueOfCurrentInput <= (numberOfInputs); ++valueOfCurrentInput) | |
{ | |
cout << "[" << valueOfCurrentInput << "] = "; | |
cin >> valueOfCurrentInput; | |
sum += valueOfCurrentInput; | |
} | |
// Calculate average. | |
avg = sum / numberOfInputs; | |
// Show average. | |
cout << "Average = " << avg << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment