I am wrote a stack example but it shows a error message when compiled.
In switch case 4: exit (); this line is the problem : think
64 9 C:\Users\pavilion 15\OneDrive\Documents\stack.cpp [Error] return-statement with a value, in function returning 'void' [-fpermissive]
This is the error message I saw when compiling this code. Can some one please help me to solve this?
#include<stdio.h>
#include<conio.h>
#define MAX 5
int stack[MAX];
int top = -1;
void push(int);
int pop();
void display();
main(){
int choice,num;
while(1){
printf("Enter your choice\n");
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Display\n");
printf("Exit\n");
scanf("%d", &choice);
switch(choice){
case 1:
printf("Enter a number");
scanf("%d", &num);
push(num);
break;
case 2:
num = pop();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("invalid input");
}
}
}
void push(int element){
if(top == MAX-1 ){
printf("Stack OverFlow");
return;
}
top = top +1;
stack[top]=element;
}
void pop(){
int element;
if(top == -1){
printf("Stack is empty\n");
return;
}
element = stack[top];
top = top - 1;
printf("%d has been deleted", element);
return element;
}
void display(){
int i;
if(top==-1){
printf("stack is empty!");
return;
}
printf("\n\n");
for(i=top;i>0;i--)
printf("%d\n", stack[i]);
}

voidfunction.