将温度 F 更改为 C 有问题
Change temperature F to C is having issues
我刚开始学习 C 编程。所以我对通过功能改变温度有疑问。请检查这个程序,我哪里做错了?谢谢!!!
#include<stdio.h>
double f_to_c(double f);
double get_integer(void);
int main(void)
{
double a;
a = get_integer();
printf("he degree in C:%f", f_to_c(a));
return 0;
}
double get_integer(void)
{
double n;
printf("Enter the variable:");
scanf_s("%f", &n);
return n;
}
double f_to_c(double f)
{
int f, c;
c = 5.0 / 0.9*(f - 32.0);
return c;
}
`
在你的情况下,
double f_to_c(double f)
{
int f, c;
c = 5.0 / 0.9*(f - 32.0);
return c;
}
int f
正在跟踪 double f
。为变量使用其他名称。
本质上,您试图使用一个未初始化的自动局部变量来调用 undefined behavior
在get_integer函数中return类型是double,应该是integer
int get_integer(void)
{
int n;
printf("Enter the variable:");
scanf_s("%d", &n);
return n;
}
在你的其他函数 f_to_c 中,return 类型是双精度但你 return 是一个整数
double f_to_c(double f)
{
int f;
double c;
c = (5.0 / 0.9)*(f - 32.0);
return c;
}
同样在开始时,您需要将代码更改为:
int main(void)
{
int a;
a = get_integer();
printf("he degree in C:%f", f_to_c(a));
return 0;
}
更正以下代码:
#include<stdio.h>
double f_to_c(double f);
double get_integer(void);
int main(void)
{
double a;
a = get_integer();
printf("he degree in C:%lf\n", f_to_c(a));
return 0;
}
double get_integer(void)
{
double n;
printf("Enter the variable:");
scanf("%lf", &n);
return n;
}
double f_to_c(double f)
{
double c;
c = 5.0/9*(f-32);
return c;
}
如您所见:
f_to_c
中 c
变量的类型更改为双精度,因为您需要双精度 return 用于该函数
- 将 F 转换为 C 的公式不正确。
- 您的 printf 和 scanf 的格式说明符不正确。
我刚开始学习 C 编程。所以我对通过功能改变温度有疑问。请检查这个程序,我哪里做错了?谢谢!!!
#include<stdio.h>
double f_to_c(double f);
double get_integer(void);
int main(void)
{
double a;
a = get_integer();
printf("he degree in C:%f", f_to_c(a));
return 0;
}
double get_integer(void)
{
double n;
printf("Enter the variable:");
scanf_s("%f", &n);
return n;
}
double f_to_c(double f)
{
int f, c;
c = 5.0 / 0.9*(f - 32.0);
return c;
}
`
在你的情况下,
double f_to_c(double f)
{
int f, c;
c = 5.0 / 0.9*(f - 32.0);
return c;
}
int f
正在跟踪 double f
。为变量使用其他名称。
本质上,您试图使用一个未初始化的自动局部变量来调用 undefined behavior
在get_integer函数中return类型是double,应该是integer
int get_integer(void)
{
int n;
printf("Enter the variable:");
scanf_s("%d", &n);
return n;
}
在你的其他函数 f_to_c 中,return 类型是双精度但你 return 是一个整数
double f_to_c(double f)
{
int f;
double c;
c = (5.0 / 0.9)*(f - 32.0);
return c;
}
同样在开始时,您需要将代码更改为:
int main(void)
{
int a;
a = get_integer();
printf("he degree in C:%f", f_to_c(a));
return 0;
}
更正以下代码:
#include<stdio.h>
double f_to_c(double f);
double get_integer(void);
int main(void)
{
double a;
a = get_integer();
printf("he degree in C:%lf\n", f_to_c(a));
return 0;
}
double get_integer(void)
{
double n;
printf("Enter the variable:");
scanf("%lf", &n);
return n;
}
double f_to_c(double f)
{
double c;
c = 5.0/9*(f-32);
return c;
}
如您所见:
f_to_c
中c
变量的类型更改为双精度,因为您需要双精度 return 用于该函数- 将 F 转换为 C 的公式不正确。
- 您的 printf 和 scanf 的格式说明符不正确。