mardi 28 avril 2020

Terminate called after throwing an instance of 'range error' what(): 'Range Error' -1?

#include"std_lib_facilities.h"
int main()
{
  vector<double>numbers;
  cout<<"Enter any two numbers:\n";
  double two_numbers;
  //loop
  while(cin>>two_numbers){
    numbers.push_back(two_numbers);
    double vector_size = numbers.size();
    double two = 2;
    double formula_equal = 1.0/100;
    double od_ev = fmod(vector_size , two);
    //checking the conditions
    if(od_ev == 0)
      if(numbers[vector_size-1] > numbers[vector_size - 2])
        cout<<"The larger value is: "<<numbers[vector_size - 1]<<'\n'
            <<"The smaller value is: "<<numbers[vector_size - 2]<<'\n';
        if(numbers[vector_size-1] - numbers[vector_size - 2] < formula_equal)
          cout<<"These numbers are almost equal.";

      else if(numbers[vector_size-1] < numbers[vector_size - 2])
        cout<<"The larger value is: "<<numbers[vector_size - 2]<<'\n'
            <<"The smaller value is: "<<numbers[vector_size - 1]<<'\n';
        if(numbers[vector_size-2] - numbers[vector_size - 1] < formula_equal)
          cout<<"these numbers are almost equal.";

      else if(numbers[vector_size-1] == numbers[vector_size - 2])
        cout<<numbers[vector_size-1]<<" is equal to  "<<numbers[vector_size - 2]<<'\n';

      }
  }

I don't know why the compiler is showing such error I have searched a lot in google but I don't find anything related to this code please help me with this code.....I don't find any error but I am just a beginner....

Aucun commentaire:

Enregistrer un commentaire