当用户按下Q它不退出程序..什么是错的??请帮助如何退出如果用户输入q
while (true)
{
//promt to user enter or quit
cout<<" Enter five digit number please or Q to quit \n";
cin>> buf; n = atoi (buf.c_str());
cin.ignore(1000,10);
if(n == 'q' || n == 'Q')
break;
a = n % 10;
b = n/10000;
if (! a == b)
{
cout<< "This is not a palindrome \n";
continue;
}
// checking the palindrome
n = n % 10;
n = n/100;
if (a == b)
cout<<" This is palindrome\n";
else
cout<<" This is not a palindrome\n";
}
你的意思是这样的: – Aysin
if(n =='1'|| n =='1') cin >> buf; n = atoi(buf.c_str()); 休息; – Aysin
uhm,no ... if(n =='1'|| n =='1')与if(n =='1')相同,因为您在两个条件相同。我的解决方案的工作方式与Ed Heal的解决方案几乎相同,所以如果解决方案能够解决问题,那么很好,解决问题 – Sampaio