c - C 中的未知类型错误

标签 c while-loop compiler-errors switch-statement

我必须用 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", &degrees);
    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’

最佳答案

仅解决语法错误:

double fc_converter(double, fahrenheit)

应该是:

double fc_converter(double fahrenheit)

另一个错误非常相似。

关于c - C 中的未知类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42406124/

相关文章:

c++ - WHILE 循环和数据输入

c - (libwebsocket) 如何在客户端连接上发送数据包

c# - 从VS2013切换到VS2015后程序不运行

c - while 循环的错误输出

java - 编译 Java 程序后,出现错误 : incompatible types: double cannot be converted to double[]

c - 在 C 中将字符串分配给 Hostent

ubuntu - 无法在Ubuntu 13.04中安装ARToolkit

c - 将结构传递给 ISR

c - 是否可以在 C 中创建长度为一位的数据类型

python - 在 while(1) 循环中生成文件编号序列