【发布时间】:2014-05-21 19:48:32
【问题描述】:
我正在尝试编写一个小型 c 程序来使用函数执行算术运算,但遇到了一些错误。
请有人看一下这段代码并进行验证!
错误:
--------------------配置:mingw5 - CUI 调试,生成器类型: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)
代码
#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;
}
}
我正在使用 C-Free Professional 编写和编译 C 程序。我也尝试过在线 C 程序编译器。但同样的错误。
【问题讨论】:
-
请不要不断更新问题,因为人们会在答案中解决您的错误。如果需要,请发布新问题。
标签: c