lundi 26 février 2018

Range_error at memory location 0x000000158F2FF408

Doing my home exercise and stock with memory location error, the code looks fine, why it doesn't work? Could you please help me, really don't get why it comes out of range.

 #include "stdafx.h"
#include "std_lib_facilities.h"

double num;
double sumV;
double maxV;
double minV;
double avrV;

double vectorSum(vector<double> v) {

    for (int i = 0; i < v.size(); ++i) {
        sumV = sumV + v[i];
    }
    return sumV;
}
double vectorMax(vector<double> v) {
    sort(v.begin(), v.end());
    maxV = v[0];
    return maxV;
}
double vectorMin(vector<double> v) {
    sort(v.begin(), v.end());
    minV = v[v.size()];
    return minV;
}
double vectorAvr(vector<double> v) {
    avrV = vectorSum(v) / v.size();
    return avrV;
}

int main()
{
    vector<double> dif;
    cout << "Enter values of distance between two cities: " << endl;
    while (cin >> num) dif.push_back(num);
    cout << "Sum of your distances is: " << vectorSum(dif) << endl << "Minimum distance is: " << vectorMin(dif) << endl
        << "Maximum of your distance is: " << vectorMax(dif) << endl << "Avrage of your distance is: " << vectorAvr(dif) << endl;
    keep_window_open();
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire