Это моя первая программа на C, пожалуйста, будьте мягкими парнями.Ошибка компиляции с gcc: warning: format указывает тип 'int *', но аргумент имеет тип 'double *'
Я пытаюсь получить пользовательский ввод для преобразования между температурами, а также использовать коммутационный футляр для расчета преобразованных температур. Моя следующая программа бросает ошибки, как это при попытке скомпилировать его с GCC на Mac:
convertTemp.c:17:20: warning: format specifies type 'int *' but the argument has type 'double *' [-Wformat]
scanf ("%d", &Celcius);
~~ ^~~~~~~~
%lf
convertTemp.c:21:72: warning: format specifies type 'int' but the argument has type 'double' [-Wformat]
printf ("The converted temperature of %d in Fahreight is: %d\n", Celcius, Fahr);
~~ ^~~~~~~
%f
convertTemp.c:21:81: warning: format specifies type 'int' but the argument has type 'double' [-Wformat]
printf ("The converted temperature of %d in Fahreight is: %d\n", Celcius, Fahr);
~~ ^~~~
%f
convertTemp.c:25:20: warning: format specifies type 'int *' but the argument has type 'double *' [-Wformat]
scanf ("%d", &Fahr);
~~ ^~~~~
%lf
convertTemp.c:29:70: warning: format specifies type 'int' but the argument has type 'double' [-Wformat]
printf ("The converted temperature of %d in Celcius is: %d\n", Fahr, Celcius);
~~ ^~~~
%f
convertTemp.c:29:76: warning: format specifies type 'int' but the argument has type 'double' [-Wformat]
printf ("The converted temperature of %d in Celcius is: %d\n", Fahr, Celcius);
~~ ^~~~~~~
%f
6 warnings generated.
Код:
#include <stdio.h>
int main (void)
{
int choice;
double Celcius, Fahr;
printf ("Do you want to convert from C to F (1) or from F to C(2))?");
scanf ("%i", &choice);
switch(choice)
{
case 1:
printf ("Please type the temp in Celcius");
scanf ("%d", &Celcius);
Fahr = (Celcius * 9)/5;
Fahr += 32;
printf ("The converted temperature of %d in Fahreight is: %d\n", Celcius, Fahr);
case 2:
printf ("Please type the temp in Fahrenheit");
scanf ("%d", &Fahr);
Celcius = (Fahr - 32) * 5;
Celcius /= 9;
printf ("The converted temperature of %d in Celcius is: %d\n", Fahr, Celcius);
}
return 0;
}
Я не получаю ошибку о неправильном типе возврата на 'main', когда компилирую это в Linux. Вы уверены, что составляете правильный файл? – templatetypedef
Код, который вы показываете, отличается от кода, который видел компилятор. Он видел 'double main (void)'. Пожалуйста, разместите ошибки кода и компиляции, которые точно совпадают. –
обновил сообщение об ошибке. извините – TonyGW