#include <iostream>
using namespace std;
int main()
{
char answer;
cout<<"请问可以格式化您的硬盘吗?【Y/N】"<<"\n";
cin>>answer;
switch(answer)
{
case 'Y':
case 'y':
cout<<"可以 测试"<<"\n";break;
case 'N':
case 'n':
cout<<"不可以 测试"<<"\n";break;
default:
cout<<"您的输入不符合要求"<<"\n";break;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
const unsigned short ADD_SUBTRACT = 32;
const double RATIO = 9.0/5.0;
double tempIn,tempOut;
char typeIn,typeOut;
cout<<"请 以 [xx.x C] 或 [xx.x F]的格式输入一个温度:";
cin>>tempIn>>typeIn;
cin.ignore(100,'\n');
cout<<"\n";
switch(typeIn)
{
case 'C':
case 'c':
tempOut=tempIn*RATIO+ADD_SUBTRACT;
typeOut='F';
typeIn='C';
break;
case 'F':
case 'f':
tempOut=(tempIn-ADD_SUBTRACT)/RATIO;
typeOut='C';
typeIn='F';
break;
default:
typeOut='E';break;
}
if(typeOut!='E')
{
cout<<tempIn<<typeIn<<" = "
<<tempOut<<typeOut<<"\n\n";
}
else
cout<<"输入错误!,请输入任意字符结束程序"<<"\n\n";
cin.get();
return 0;
}
|