Error when debugging in Visual Studio 2015. If you enter a value greater than one then the program works, you enter less - it breaks.

#include <iostream> #include <iostream> using namespace std; int main() { int y=0, eps, i=2, s; cout << "Enter eps " << "\n"; cin >> eps; if (eps >= 1) { cout << "Error" << "\n"; } else { while (eps > s) { s = 1 / i; i++; y = y + s; } cout << "y=" << y; } return 0; } 
  • If you were really debugging, you would have localized the problem. - αλεχολυτ

1 answer 1

Integer division s = 1 / i; with your i>=2 always gives 0. Work with double variables, for example, and instead of 1 write 1.0 .