我必须在C中创建一个允许用户输入程度和数字的程序。我现在正在学习C,很难说我是否正确行事。我不知道为什么我会得到这些未知的类型名称。我想假设使用switch语句,while循环和转换器函数。
/* Fahrenheit/Celsius Converter */
#include <stdio.h> /* definitions of printf, scanf */
#include <math.h> /* definitions of sqrt, pow */
#define FCR 0.556 /* defines the value for FCR */
#define CFR 1.8 /* defines the value for CFR */
double fc_converter(double);
double cf_converter(double);
int
main(void)
{
double fahrenheit;
double celsius;
char degrees;
printf("Hello > Fahrenheit/Celsius Converter. Please enter F or C:");
scanf("%c", °rees);
while (degrees == 'F' || 'f' || 'c' || 'C' )
{
switch(degrees){
case 'F':
case 'f':
printf("Hello > Please enter a Fahrenheit degree number:");
scanf("%lf", &fahrenheit);
return(fc_converter(fahrenheit));
break;
case 'C':
case 'c':
printf("Hello > Please enter a Celsius degree number:");
scanf("%lf", &celsius);
return(cf_converter(celsius));
break;
default:
printf("The input is unknown!");
break;
}
break;
}
}
double fc_converter(double, fahrenheit)
{
if (fahrenheit >= -200) && (fahrenheit <= 200)
{
celsius = FCR * (fahrenheit - 32.00);
printf("The calculated value from the converter function is:%.2f", fahrenheit);
return celsius;
}
else
{
printf("Invalid Celsius temperature.");
return (celsius = sqrt(fahrenheit));
}
}
double cf_converter(double, celsius)
{
if(celsius >= - 200) && (celsius <= 200)
{
fahrenheit = CFR * celsius + 32.00;
printf("The calculated value from the converter function is:%.2f", celsius);
return fahrenheit;
}
else
{
printf("Invalid Fahrenheit temperature.");
return(fahrenheit = pow(celsius, 3));
}
}
错误:
HW3.c:44:22: error: unknown type name ‘fahrenheit’
HW3.c:61:22: error: unknown type name ‘celsius’
答案 0 :(得分:0)
您的功能签名不正确。您在参数类型和参数名称之间使用逗号。逗号用于分隔方法签名中的参数。
double fc_converter(double, fahrenheit)
应该是
double fc_converter(double fahrenheit)
和
double cf_converter(double, celsius)
应该是
double cf_converter(double celsius)