Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kdmkdmkdm/2552781 to your computer and use it in GitHub Desktop.

Select an option

Save kdmkdmkdm/2552781 to your computer and use it in GitHub Desktop.
(24): error C2065: 'i' : undeclared identifier
// giAverage2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
//declare
int valuesToAverage = 0;
float valueOfCurrentInput = 0.0f;
float sum = 0.0f;
float avg = 0.0f;
cout << "Enter the number of values to average: ";
cin >> valuesToAverage;
//find sum
for(int i = 0; i <= (valuesToAverage - 1); ++i)
{
cout << "[" << i << "] = ";
cin >> valueOfCurrentInput;
sum += valueOfCurrentInput;
//calculate average
avg = sum / valuesToAverage;
}
// Show Average.
cout << "Average = " << avg << endl;
}
// giAverage2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
//declare
int valuesToAverage = 0;
float valueOfCurrentInput = 0.0f;
float sum = 0.0f;
float avg = 0.0f;
cout << "Enter the number of values to average: ";
cin >> valuesToAverage;
//find sum
for(int i = 0; i <= (valuesToAverage - 1); ++i);
{
cout << "[" << i << "] = ";
cin >> valueOfCurrentInput;
sum += valueOfCurrentInput;
//calculate average
avg = sum / valuesToAverage;
}
// Show Average.
cout << "Average = " << avg << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment