冲突类型在C用户定义的函数 [英] confliction type for a user defined function in c
问题描述
我的工作在C长time.Here后,我一定要实现三个功能,其中包括
- 得到一个编号,并显示一半
2.注册数的平方
3.Get第二把交椅,并展示自己的总结和sabtraction。
我使用DEVC ++,当我编译codeI得到我在冲突的类型,如果squareInput
。什么是错在这里标题中提到的错误:
#包括LT&;&stdio.h中GT;
#包括LT&;&CONIO.H GT;
诠释主(){ 浮X;
的printf(请输入一个数字\\ n);
scanf函数(%F,&安培; X); //任务1:数字显示一半
pirntf(x的一半是=%.3f中,x); //任务2:数平方 squareInput(X); //从这里调用方函数 //任务3:获得两个数字并显示两者总和与sabtraction 浮NUM1,NUM2; //声明两个浮点数(浮点数可容纳小数点的数字
的printf(请输入NUM1 \\ n);
scanf函数(NUM1是=%F,&安培; NUM1);
的printf(请输入NUM2 \\ n);
scanf函数(NUM2是=%F,NUM2);
计算(NUM1,NUM2); //调用函数计算 残培();
}浮squareInput(浮动输入){ 浮广场=输入*输入;
的printf(数\\ n平方%.3f \\ n,广场);
返回0;
}计算浮动(浮动NUM1,NUM2浮动){ //总和
浮总和= NUM1 + NUM2; //声明antoher变量称为总和持有的总和
// sabtraction
浮sabtraction = NUM1,NUM2; 的printf(总和为%.2f \\ n,求和);
的printf(sabtraction为%.2f \\ n,sabtraction); 返回0;
}
事情会出问题没有原型。添加
浮动squareInput(浮动输入);
计算浮动(浮动NUM1,NUM2浮动);
在前INT主要()
。
如果您它被称为前不申报的函数,编译器假定它作为INT-返回函数。然而, squareInput()
收益浮动,所以编译器(或连接器,也许)抱怨你。
另外请注意,定义声明(而不是相反,很明显),因此移动 squareInput的定义()
和计算()
中,他们被称为前面的地方太多工作。
I am working in c after a long time.Here i have to achieve three functionality which includes
- get a number and show half
2.Get the square of the number
3.Get two number and show their summation and sabtraction.
I am using devC++ and when i compile the code i get the error i mentioned in the title which conflict type if squareInput
.What is wrong here:
#include<stdio.h>
#include<conio.h>
int main(){
float x;
printf("enter a number\n");
scanf("%f",&x);
//TASK 1 : display half of the number
pirntf("half of x is = %.3f",x);
//TASK 2 : square of number
squareInput(x); //call square function from here
// TASK 3 : get two numbers and display both summation and sabtraction
float num1,num2; // declare two floating number( floating numbers can hold decimal point numbers
printf("enter num1 \n");
scanf("num1 is =%f",&num1);
printf("enter num2 \n");
scanf("num2 is =%f",num2);
calculate(num1,num2);// call calculate function
getch();
}
float squareInput(float input){
float square=input*input;
printf("\n square of the number is %.3f \n",square);
return 0;
}
float calculate(float num1,float num2){
//summation
float summation= num1+num2; // declare antoher variable called summation to hold the sum
//sabtraction
float sabtraction=num1-num2;
printf("summation is %.2f \n",summation);
printf("sabtraction is %.2f \n",sabtraction);
return 0;
}
Things will go wrong without prototypes. Add
float squareInput(float input);
float calculate(float num1,float num2);
in front of int main()
.
If you don't declare a function before it's called, the compiler assumes it as a int-returning function. However, squareInput()
return float, so the compiler(or linker, maybe) complains to you.
Also note that definitions are declarations(but not vice versa, obviously), so moving the definitions of squareInput()
and calculate()
in front of where they are called works too.
这篇关于冲突类型在C用户定义的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!