【发布时间】:2016-02-16 15:05:18
【问题描述】:
我在 c 中工作了很长时间。在这里我必须实现三个功能,其中包括
- 得到一个数字并显示一半
2.得到数字的平方
3.得到两个数并显示它们的和和减法。
我正在使用 devC++,当我编译代码时,我得到了我在标题中提到的错误 conflict type if squareInput。这里有什么问题:
#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;
}
【问题讨论】:
-
由于代码是用C++编译的,请去掉
c标签。 -
头文件
conio.h不可移植。建议用getchar()替换对getch()的调用并删除#include <conio.h>语句