2017-02-23 30 views
-2

Мне нужно создать программу на C, которая позволяет пользователю вводить, градусы и цифры. Я изучаю C сейчас, и мне трудно сказать, правильно ли я делаю это. Я не уверен, почему я получаю это неизвестное имя типа. Я предполагаю использовать оператор switch, while loop и функцию преобразователя.Неизвестный тип Ошибка в C

/* 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’ 
+2

'(double, fahrenheit)' -> '(double fahrenheit)' – JETM

+2

Прочитайте свой код в строках ошибки. Например, 'ouble fc_converter (double, fahrenheit)' - то, что компилятор должен думать «Фаренгейт», находится в этом объявлении. –

+0

@JETM После этого я дал ошибку HW3_fip.c: В функции 'fc_converter': HW3_fip.c: 46: 29: ошибка: ожидаемый идентификатор до '(' токен HW3_fip.c: В функции 'cf_converter ': HW3_fip.c: 61: 26: ошибка: ожидаемый идентификатор до' ('токен – struggling

ответ

0

адресация только синтаксические ошибки:

double fc_converter(double, fahrenheit) 

Должно быть:

double fc_converter(double fahrenheit) 

Другая ошибка очень похож.

0

Неправильная подпись вашей функции. У вас есть запятая между типом аргумента и именем аргумента. Для разделения аргументов в сигнатуре метода используется запятая.

double fc_converter(double, fahrenheit)

должно быть

double fc_converter(double fahrenheit)

И

double cf_converter(double, celsius)

должно быть

double cf_converter(double celsius)

Смежные вопросы