読んでいない場合は、if文は、変数選択肢を無視しているようだと選択肢が「L」または「L」であるかのようにプログラムが継続的に実行されます。は、ステートメントがchar変数を適切に
if文が無視される理由は何ですか?私はプログラムの実際のコードを省略しました。
#include <iostream>
using namespace std;
void starLeftTriangle(int n);
void starRightTriangle(int n);
int main() {
int star;
char choice;
cout << "Input the number of stars you want to draw: \n";
cin >> star;
cout << "Would you like to draw a left triangle, right triangle, or quit? \n";
cin >> choice;
cout << "The choice value is " << choice << endl;
system("pause");
while (choice != 'q' || 'Q'){
if (choice == 'l' || 'L'){
starLeftTriangle(star);
}
else if (choice == 'r' || 'R') {
starRightTriangle(star);
}
}
if (choice == 'q' || 'Q') {
cout << "Quitting Program.";
}
else{
//throw error
}
return 0;
}
'選択肢を!= 'q' || 「Q」はあなたが思っていることをしません。それは ''選択 ''が '' q ''でないか、 '' Q''が真であり、後者が常に真であることを意味します。 – Biffen