How to correct this

#include <bits/stdc++.h>
using namespace std;

int main(){

int q;
cin>>q;
stack<int>s;
while(q--){
	int m;
	cin>>m;
	if(m==1){
		if(!s.empty()){
			int val = s.top();
			cout<<val<<endl;
			s.pop();
		}
	}
	else{
		int val;
		cin>>val;
		s.push(val);
	}
}

}

Hello @talhashamim001 what is the error that you are getting?

Could you please tell what is the question or you are trying to do so that we can find error fast.

I don’t have access to your course.
You have to share either the screenshot or the question name.

Though I have checked your code is giving the expecting output according to the Input.
check this:
https://ide.codingblocks.com/s/421077
i have commented the mistake:
Happy Learning!!

thank you…

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.