Lets write something closer to real C++ code. I've put the comments inside the code for convenience.
Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
// In C++ we don't declare all variables up front at the start of our function.
// instead the normal thing to do is to declare them near their point of first use.
// That way, if we were to say exit this function say when the user entered a negative
// number then the program wouldn't have wasted time initialising the vector. Not too
// important here obviously, but it can become very important in a larger program.
int numberOfElements = 0;
// A while loop was not appropriate here. That's because you intended the loop to
// always be run at least once. The way to do that is not to assign a value to make
// the condition true beforehand, but to make it a "do .. while" instead. That's what
// they're for! In this instance a for (;;) loop with a break statement would work at
// least as well too though, and save testing for the same condition twice.
do {
cout << "How many numbers will you be entering?" << endl;
cin >> numberOfElements;
cin.ignore();
if (numberOfElements <= 0) {
// You had two semi-colons on this line before.
cout << endl << "Error... Please enter a positive integer" << endl;
}
} while (numberOfElements <= 0);
cout << " Enter the numbers:\n\t\t\t";
// Why use \n all of a sudden instead of endl? endl doesn't have to go at the end
// The vector only gets initialised once we reach this line.
vector<int> array;
// vectors already keep track of how many items they contain. You're not supposed to
// also track it separately in a variable of your own. Simply use the .size() method to find
// out how many items it holds. arrayNumber and the finished flag were not needed.
while (array.size() < numberOfElements) {
int temp; // Nothing outside this loop needs to even know temp existed, so here is a good place for it.
cin >> temp;
array.push_back(temp);
cin.ignore();
}
// sum and loopNumber can be declared here. as loopNumber is just a for-loop
// counter the normal thing to do is to declare it inside the for loop. Personally
// I would use a shorter name.
float sum = 0;
// It's safer to use array.size() here in case the code changes later.
for (size_t loopNumber = 0; loopNumber < array.size(); loopNumber++) {
sum += array[loopNumber];
}
// Serious C++ programmers would replace the loop above with one call to std::accumulate
// Also pay attention to the clean use of whitespace in this code vs what was posted earlier
cout << "Average equals: " << sum / numberOfElements;
cin.get();
}
P.S. The grammatical error in Elysia's sig always bothers me. ("every thing" should be "everything")
You don't have to feed Elysia's ego anyway