该代码无法正常工作,请帮助我。即使我输入了正确的字符,它仍然要求“输入正确的数字”。并且它不评估条件。
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
int main()
{
char ch = '0';
A:
cout << "enter a Character" << endl;
cin >> ch;
if ((ch != 'X')||(ch != 'x'))
{
cout << "Please Enter Right Number" << endl;
goto A;
}
return 0;
}
use
if ((ch != 'X') && (ch != 'x'))
代替
if ((ch != 'X')||(ch != 'x'))
也可以代替使用goto
你可以使用循环
cout << "enter a Character" << endl;
cin >> ch;
while(ch!='X' && ch!='x')
{
cout << "Please Enter Right Number" << endl;
cout << "enter a Character" << endl;
cin>>ch;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)