Skip to content

Instantly share code, notes, and snippets.

@kdmkdmkdm
Created April 22, 2012 07:41
Show Gist options
  • Save kdmkdmkdm/2462542 to your computer and use it in GitHub Desktop.
Save kdmkdmkdm/2462542 to your computer and use it in GitHub Desktop.
sumReddit2CPlusPlus
// sumReddit2
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
// Declare.
int numberOfInputs = 0;
float valueOfCurrentInput = 0.0f;
float sum = 0.0f;
cout << "Enter the number of values to sum: ";
cin >> numberOfInputs;
for(float valueOfCurrentInput = 0.0f; valueOfCurrentInput <= (numberOfInputs); ++valueOfCurrentInput)
{
cout << "[" << valueOfCurrentInput << "] = ";
cin >> valueOfCurrentInput;
sum += valueOfCurrentInput;
}
// Show sum.
cout << "Sum = " << sum << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment