debug this code asap | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

debug this code asap

#include<iostream> using namespace std; #define max 5 int stack[max] ,top =-1 ; void push(int); int pop(); int main() { int choice, num; while(1) { cout<<"Enter your choice\n1. push\n2. pop\n3. display\n4.exit\n"; cin>>choice; switch(choice) {case 1:{ cout<<"enter a number to be inserted : "; cin>>num; push(num); break; } case 2 :{ num = pop(); break;} case 3:{ void display(); break; } case 4:{exit(1); break; } default : cout<<"invalid choice"; } } } void push(int element) { if(top == max-1) {cout<<"stack overflow\n"; return; } top = top+1; stack[top]=element; } int pop() { int element; if(top==-1) { cout<<"stack underflow"; return; } element = stack[top]; top = top -1; cout<<"the element that has been deleted is"<<element<<endl; return element; } void display() { if(top == -1) {cout<<"stack is empty\n"; return; } cout<<"\n\n"; for(int i=top;i>=0;i++) {cout<<endl<<stack[i]; } }

14th Nov 2019, 9:00 PM
Shikher Jaitly
Shikher Jaitly - avatar
1 Answer
+ 2
first try to post it in playground
15th Nov 2019, 3:59 PM
Rohit Kh
Rohit Kh - avatar