请问,我的vc程序错在哪了

来源:百度知道 编辑:UC知道 时间:2024/05/11 05:55:06
这是一个关于摄氏温度与华氏温度转化的问题(C代表摄氏温度,F代表华氏温度),我写了两个代码,第一个没报错但不能实现应有功能,第二个报错:
一、
#include <iostream>
using namespace std;

int main()
{float t,c,f;
char ch;
cout<<"Please input the temperature number: ";
cin>>t;
cout<<endl;
cout<<"Please choose the type of temperature,C or F?";
cin>>ch;
cout<<endl;

if (ch=='c'||'C')
{
f=(9.0/5.0)*t+32;
cout<<"The F temperature is "<<f<<"F."<<endl;
cout<<"Thank you."<<endl;
}
else if (ch=='f'||'F')
{
c=(5.0/9.0)*(t-32);
cout<<"The C temperature is "<<c<<"C."<<endl;
cout<<"Thank you."<<endl;
}
else cout<<"The type of temperature is wrong!"<<endl;
retu

第一个是你的IF语句有问题,改成如下IF(CH=='C' | CH=='c'),类似这样。

第二个代码是你用的case语句有问题。

去掉所有的break

另外,判断大小写的语法最好是用uppercase