求解答!
#include <iostream>#include <string>
#define full 100
using namespace std;
class Car
{
public:
string color;
int size;
int oil;
public:
int runing ();
int addoil ( int x );
void printcar ();
};
int main()
{
Car mix;
mix.color = "萝莉白";
mix.size = 3;
mix.oil = full;
int d;
char t;
int z;
int i;
for ( ; ( i = mix.runing() ) != 0 ; )
{
cout << "我曾经跨过山和大海!" << endl;
cout << "剩余油量:" << mix.oil << endl;
if( i <= 10)
{
cout << "boss要加油吗?(Y/N)" << endl;
cin >> t;
if( t == 'Y'||'y' )
{
cout << "请输入加油量(1-100):" << endl;
cin >> d;
if( z = mix.addoil( d ) )
{
cout << "加油成功!" << "剩余:" << z << endl;
}
else
{
cout << "没钱加什么油!" << endl;
}
}
else
{
if( t == 'N'||'n' )
{
cout << "油不多了!" << endl;
}
else
{
cout << "Error!!!" << endl;
}
}
}
}
cout << "油已经耗尽!" << endl;
mix.printcar();
return 0;
}
int Car::runing()
{
oil--;
return oil;
}
int Car::addoil( int x )
{
oil += x;
return oil;
}
void Car::printcar()
{
cout << "颜色:" << color << '\n'
<< "大小:" << size << '\n'
<< "最大油量:100 " << endl;
}
为什么输入N还是,相当于输入了Y。
为什么N输入木有用。 if(t == 'Y' || 'y')
0087608D 0F BE 45 B3 movsx eax,byte ptr
00876091 83 F8 59 cmp eax,59h
00876094 74 0D je main+143h (08760A3h)
00876096 B8 79 00 00 00 mov eax,79h
0087609B 85 C0 test eax,eax
0087609D 0F 84 D1 00 00 00 je main+214h (0876174h)
if( (t == 'Y') || 'y')
0132608D 0F BE 45 B3 movsx eax,byte ptr
01326091 83 F8 59 cmp eax,59h
01326094 74 0D je main+143h (013260A3h)
01326096 B8 79 00 00 00 mov eax,79h
0132609B 85 C0 test eax,eax
0132609D 0F 84 D1 00 00 00 je main+214h (01326174h)
if(t == 'Y' || 'y') 和 if( (t == 'Y') || 'y') 一个效果,这不是你想要的对吧?
人造人 发表于 2018-3-9 00:59
if(t == 'Y' || 'y') 和 if( (t == 'Y') || 'y') 一个效果,这不是你想要的对吧?
聪明
谢谢了
页:
[1]