Stack problem prateek Sir and coding

pls tell me why my code gives output run time error and also explain with your code
#include
#include
using namespace std;
int main(int argc, char const *argv[]){

stack<int> s;
int no;
cin>>no;

int input;
int c;
while(no--){
  
    cin>>input;
  
 if(input==2){
    
   cin>>c;
  s.push(c);
    }
if(input==1){
  if(s.empty()){
		cout<<"No Code"<<endl;
	}
   cout<<s.top()<<endl;
      s.pop();
      
}

}

return 0;

}

@kshitiz.gzb
The runtime error is due to the statements
cout<<s.top()<<endl;
s.pop();
Particularly in the case when stack is empty.
You need to put the above two statements inside in an else block otherwise your code tries to print the top element and pop it even when the stack is empty giving you a runtime error.
Make this change and the rest of your code works fine.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.