0

以下のこのコードは、入力が正しいかどうかに関係なく機能しません。入力が正しい場合でも、何らかの理由でifステートメントが実行されます。簡単な提案があれば役に立ちます。

char status;

cout<<"Please enter the customer's status: ";
cin>>status;

if(status != 'P' || 'R')
{

    cout<<"\n\nThe customer status code you input does not match one of the choices.\nThe calculations that follow are based on the applicant being a Regular customer."<<endl;

    status='R';
}
4

2 に答える 2

3

ですif(status != 'P' || status != 'R')

それでも、ロジックはちょっとオフです。論理ORをチェーンすることはできません(または論理演算子のいずれか)。おそらく、次のようなものを使用する必要があります。if(status != 'P' && status != 'R')

于 2013-02-03T03:42:42.580 に答える
2
if ('R')

常にtrueと評価されるため、if(status != 'P' || 'R')常にtrueと評価されます。

変化する

if(status != 'P' || 'R')

if(status != 'P' && status != 'R')

また

if(status == 'P' || status == 'R')

最後のバージョンはあなたが望むものをより明確に見ることができるかもしれませんか?

于 2013-02-03T03:43:06.853 に答える