C编程程序只打印在我的变量的第一个值 [英] C programming program only printing the first value in my variable
本文介绍了C编程程序只打印在我的变量的第一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
程序只显示32时,我把它打印NewTemp
NewTemp = 32 +输入* 180/100;这部分似乎是主要的问题。
的#include<&stdio.h中GT;浮动摄氏度(浮动输入){
浮NewTemp;
** NewTemp = 32 +输入* 180/100;
的printf(请输入温度值转换为华氏\\ n);
scanf函数(%F,&安培;输入);
的printf(摄氏温度为:%F \\ N,NewTemp); 返回NewTemp;}诠释主要(无效){
浮CelToFahren,输入;
CelToFahren =摄氏度(输入);
}
解决方案
在读取输入之前,你自己算算。你需要做的周围用另一种方式。
此外,没有理由通过一项无意义的和未初始化值到摄氏
功能。
最后, 180/100
是1其余80,因为当你把两个整数,你会得到整数除法。您可以使用 180.0 / 100.0
。
基本上,你需要学习C
Program only displaying the 32 for when I have it print "NewTemp" NewTemp = 32 + input * 180/100; this part seems like the main problem
#include <stdio.h>
float celsius(float input) {
float NewTemp;
**NewTemp = 32 + input * 180/100;
printf("Please enter the temperature value to convert to fahrenheit\n");
scanf("%f", &input);
printf("The temperature in celsius is: %f\n", NewTemp);
return NewTemp;
}
int main(void){
float CelToFahren, input;
CelToFahren = celsius(input);
}
解决方案
You do the math before you read the input. You need to do it the other way around.
Also, there's no reason to pass a meaningless and uninitialized value to the celsius
function.
Lastly, 180/100
is 1 remainder 80 because when you divide two integers, you get integer division. You can use 180.0/100.0
.
Basically, you need to learn C.
这篇关于C编程程序只打印在我的变量的第一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文