If you're really interested in learning C++, you should look for alternatives (that is, a good book), as this sample code indicates that your professor is not very competent in C++.
int main()
{
int n [7] = {12, 22, 34, 43, 45, 54, 99};
float x, sum, avg;
sum = 0;
cout << "How many numbers? "; //You already have the numbers in your n array, why are you doing this??
cin >> ; //This is obviously wrong
for (count=1; count<=n; count++)
{
cout << "? "; //This is not needed, because ----v
cin >> x; //Again, you already have the numbers. Don't ask the user for numbers you already have!
sum = sum + x; //Shouldn't you be adding up the numbers in your n array?
}
avg = sum / n; //You can't divide by an array like this!
cout << "The average is " << avg << endl;
return 0; //successful termination
}
#include <iostream>
usingnamespace std;
int main()
{
float InputData[100]; //array to hold all of the data being input
int numOfInputs = 0; //A variable that holds how many inputs there will be
cout << "How many numbers will be entered? : ";
cin >> numOfInputs; //give numOfInputs the amount of numbers that will be input
//Make sure that numOfInputs isn't greater than 100, or less than 1.
//Checking to make sure that your values are in the appropriate range is always
//good practice.
if(numOfInputs > 100 || numOfInputs < 1)
{
//if the number is out of range, tell the user, and exit the program.
cout << "You entered an invalid number" << endl;
return 1;
}
//Now we need to assign data to our array. You do this almost the same way
//you did originally
for(int i = 0; i < numOfInputs; ++i)
{
//Each time a for loop runs, the variable 'i' will increment.
//because of this, we can use it as our subindex (or position) that our
//data will be assigned to.
cin >> InputData[i];
}
//After you get all the data.. well the rest seems obvious. Do the math..
float sum = 0;
for(int i = 0; i < numOfInputs; ++i)
{
sum += InputData[i]; //add all of the data to sum
}
float average = sum / numOfInputs;
return 0;
}
Well.. I typed a really detailed explanation to this, but i refreshed my page and now its all gone.. fail.
I'm gonna forward you to this page about arrays. read it, love it. http://cplusplus.com/doc/tutorial/arrays/
The program above is a nice way to get an average using arrays, assuming a fixed number of inputs. You can further add on to that to meet your programs needs.