
C++ F转到C, 为什么不可运行说Error3 error C4700: uninitialized local variable 'Celsius' used
int_tmain(intargc,_TCHAR*argv[]){floatFahrenheit;//toholdtemperatureinFahrenheitcharC...
int _tmain(int argc, _TCHAR* argv[])
{
float Fahrenheit; // to hold temperature in Fahrenheit
char Celsius; // to hold temperature in Celsius
// set the numeric output formatting.
cout << fixed << showpoint << setprecision(1);
// Display the table headings.
cout << "Fahrenheit\ tCelsius " << endl ;
cout << "---------------------" << endl ;
//Display the temperature.
for (Fahrenheit = 0.0; Fahrenheit <= 100.0; Fahrenheit += 10)
{
// Calculate Celsius
Fahrenheit = (5.0 / 9.0) * (Fahrenheit - 32);
// DDisplay the temperature in Fahrenheit and Celsius.
cout << Fahrenheit << "\t" << Celsius << endl;
}
return 0;
} 展开
{
float Fahrenheit; // to hold temperature in Fahrenheit
char Celsius; // to hold temperature in Celsius
// set the numeric output formatting.
cout << fixed << showpoint << setprecision(1);
// Display the table headings.
cout << "Fahrenheit\ tCelsius " << endl ;
cout << "---------------------" << endl ;
//Display the temperature.
for (Fahrenheit = 0.0; Fahrenheit <= 100.0; Fahrenheit += 10)
{
// Calculate Celsius
Fahrenheit = (5.0 / 9.0) * (Fahrenheit - 32);
// DDisplay the temperature in Fahrenheit and Celsius.
cout << Fahrenheit << "\t" << Celsius << endl;
}
return 0;
} 展开
展开全部
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
double Fahrenheit; // to hold temperature in Fahrenheit
double Celsius; // to hold temperature in Celsius
// set the numeric output formatting.
cout << fixed << showpoint << setprecision(1);
cout << setw(12);
cout.setf(ios_base::right,ios_base::adjustfield);
// Display the table headings.
cout << "Fahrenheit(°F) -- Celsius(°C)\n";
cout << "---------------------\n";
//Display the temperature.
for (Fahrenheit = -40.0; Fahrenheit <= 110.0; Fahrenheit += 10) {
// Calculate Celsius
Celsius = (5.0 / 9.0) * (Fahrenheit - 32);
// DDisplay the temperature in Fahrenheit and Celsius.
cout << setw(6) << Fahrenheit << "\t" << setw(12) << Celsius << endl;
}
return 0;
}
追问
已经解决了,太谢谢你啦:)
追答
char Celsius; -> double Celsius;
Fahrenheit = (5.0 / 9.0) * (Fahrenheit - 32); -> Celsius = (5.0 / 9.0) * (Fahrenheit - 32);
展开全部
Celsius 这个变量没初始化
追问
昂~应该如何改呢?不太懂这些,是个选修课- -好头疼
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
‘Celsius’ 这个变量 你用到了吗?
追问
我也不太懂这些东西,我是照着KPH到MPH弄的,不知道哪里出了问题。就是想运行出来显示
Farenheit Celsius
-------------------------------
0.0 -17.8
10.0 -12.2
一直到100
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询