-3

単一の文字を評価しようとしています:

bool repeat = true;
while (repeat)

//code

char x;
    cout << "Would you like to tansfer another file? Y/N ";
    cin >> x;

    if (x == 'y' || x == 'Y')
        repeat = true;
    if (x == 'n' || x == 'N')
        repeat = false;
    else
        throw "Input error";

コンソール出力として Input Error が表示され続けます。理由はありますか?while ループを繰り返すことができません。

4

2 に答える 2

6

あなたはここに欠けていelseます:

if (x == 'n' || x == 'N')

次のようにする必要があります。

else if (x == 'n' || x == 'N')

入力とステートメントwhileを囲むために、の後に中括弧を追加する必要があります。if

于 2013-10-01T15:47:13.713 に答える
4

{}次の中括弧を忘れますwhile:

while (repeat)
{

  char x;
  cout << "Would you like to tansfer another file? Y/N ";
  cin >> x;

  if (x == 'y' || x == 'Y')
      repeat = true;
  else
  if (x == 'n' || x == 'N')
      repeat = false;
  else
      throw "Input error";

}
于 2013-10-01T15:47:38.150 に答える