私の CS の本で、ソース コードが次のような C++ プログラムを見ました。
#include <iostream>
using namespace std;
int main()
{
char choice=‘y’; //why is this required?
int marks, classx, test;
while (choice=='y'||choice==‘Y') {
cout<<"Enter marks:";
cin>>marks;
cout<<"\nEnter class:";
cin>>classx;
cout<<"\nWant to Enter more? (y/n)";
cin>>choice; //Can't understand why **choice** is assigned **'y'** before while loop?
}
return 0;
}
このコードでは、ループの'y'
前に文字を割り当てた理由がわかりません。5 行目でwhich assignswhile
の値を省略しましたが、その後はエラーが表示されなくても実行されません!choice
'y'
ループの前'y'
に文字を割り当てた理由を説明してください。choice
while
私はプログラミングの世界の初心者であり、C ++から始めたことに注意してください