Hi,

I'm trying to make a program that reads numbers from a file into a vector. Then find the highest, lowest, average, and total of the numbers. The problem I am having is reading the numbers into the vector. My while loop doesn't return true and I'm not sure why. I also tried using the get() function, but that didn't work either. I'm not sure what kind of expression I could use to say "while there are more numbers in the file" Also, when I run the program a box comes up saying "Program stopped working, checking for solutions" It gives me three (which means my getAverage() never runs) WRONG numbers and tells me the program stopped working.

Here is my whole code --

Code:
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;

//function prototypes
int getLowest(vector<int> theVector);   
int getHighest(vector<int> theVector);
int getTotal(vector<int> theVector);
int getAverage(vector<int> theVector);


vector <int> numArray;     //the vector to hold the numbers

int main(int argc, char *argv[]) {
    string filepath;
    cout<<"Please enter a file path."<<endl;
    cin>>filepath;
    ifstream theFile(filepath.c_str());     //make an ifstream for the given path
    if(!theFile.is_open())                  //if it couldn't be opened...
         cout<<"File could not be opened!"<<endl;  
    else {
         int x;
         while(theFile >> x) {    //while there is a next int in theFile
             cout<<"test"<<endl;
             numArray.push_back(x);       //push_back next int onto numArray
         }
         if(numArray.empty())  {
                  cout<<"numArray is empty!!"<<endl;
         }
         cout<<"The lowest number here is "<<getLowest(numArray)<<"."<<endl;
         cout<<"The highest numer here is "<<getHighest(numArray)<<"."<<endl;
         cout<<"The total of the numbers are "<<getTotal(numArray)<<"."<<endl;
         cout<<"The average of the numbers is "<<getAverage(numArray)<<"."<<endl;
         theFile.close();
    }    
    cin.get();
    cin.ignore();
    
}

//go through vector and find smaller values
int getLowest(vector<int> theVector) {
    int lowest = 100000000;
    for(int i=0;i < theVector.size();i++) {
            if(lowest > theVector[i]) 
                      lowest = theVector[i];
            }
    return lowest;
}

//go through vector and find larger values
int getHighest(vector<int> theVector) {
    int highest = 0;
    for(int i=0;i < theVector.size();i++) {
            if(highest < theVector[i])
                       highest = theVector[i];
            }    
    return highest;
}

//get total of all the numbers in the vector
int getTotal(vector<int> theVector) {
    int total = 0;
    for(int i=0;i < theVector.size();i++) 
            total += theVector[i];
    return total;    
}

//get the average of all numbers in the vector
int getAverage(vector<int> theVector) {
    return (getTotal(theVector) / theVector.size());      
}
Can anyone help me out here? It would be very appreciated