I am trying to write a small c-program to perform arithmetic operations using functions, but facing some error.
Can some one please have a look on this code and verify it, please!
Error:
--------------------Configuration: mingw5 - CUI Debug, Builder Type: MinGW--------------------
Checking file dependency...
50: error: cannot convert `div_t' to `int' in assignment
64: error: a function-definition is not allowed here before '{' token
69: error: a function-definition is not allowed here before '{' token
74: error: a function-definition is not allowed here before '{' token
79: error: a function-definition is not allowed here before '{' token
84: error: a function-definition is not allowed here before '{' token
90:2: warning: no newline at end of file
Complete Make Untitled25: 6 error(s), 1 warning(s)
CODE
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int add(int, int);
int sub(int, int);
int mul(int, int);
int divs(int, int);
int print(int);
int main(){
int ans,a,b,n;
printf("******************");
printf("\n1 ADD");
printf("\n2 SUB");
printf("\n3 MUL");
printf("\n4 DIV");
printf("\n5 EXT");
printf("\n******************");
printf("\n\n\nEnter Your Option(1-5):");
scanf("%d",&n);
// n=1;
printf("\nEnter Values a,b:");
scanf("%d%d",&a,&b);
// a=1;b=2;
if(n==4&&b==0){
printf("\n\n Value of `B` Can't Be `0` for Division\n\n");
exit(EXIT_SUCCESS);
}
if(n>0&&n<6){
if(n==1){
ans=add(a,b);
// main();
}
if(n==2){
ans=sub(a,b);
// main();
}
if(n==3){
ans=mul(a,b);
// main();
}
if(n==4){
ans=divs(a,b);
// main();
}
if(n==5){
exit(EXIT_SUCCESS);
}
print(ans);
}
else {
printf("\nWorng Entry!\n ");
exit(EXIT_SUCCESS);
}
int add(int a,int b){
ans=a+b;
return(ans);
}
int sub(int a,int b){
ans=a-b;
return(ans);
}
int mul(int a,int b){
ans=a*b;
return(ans);
}
int divs(int a,int b){
ans=a/b;
return(ans);
}
int print(int ans){
printf("\n\n Answer = %d",ans);
return;
}
}
I am using C-Free Professional to write and compile C Programs. I have tried on-line C-Program Compilers also. But same error.