You can initiate stops as an array I guess(int stops[turn]) as C++ now offers to allocate memory this way even inside any function. That may solve your problem.
Alongside you will have to check corner cases as your highest_total variable may provide garbage value. So while declaring the variable assign a value to it. I prefer initializing int highest_total=-1 here.
Actually you dont need an array or pointer here. This can be solved this way-
#include<cstring> #include<algorithm> using namespace std; int main() { int turn,get_off,get_on,total_passenger;total_passenger=0; cin>>turn; int highest_total=-1; for(int i=0;i<turn;i++){ cin>>get_off>>get_on; total_passenger=get_ontotal_passenger=total_passenger+get_on-get_off; if(total_passenger>highest_total) highest_total=total_passenger; } cout<<highest_total<<endl; return 0; }