我的目標是創建一個C++程序,它會重複執行一段代碼,直到用戶輸入適當的值並使用while循環執行。我的代碼只是一遍又一遍地重複着,即使我輸入「0」,它仍然會重複循環中的代碼塊。C++雖然循環中斷
這裏是我的源代碼:
#include <iostream>
using namespace std;
int main()
{
int num = 0;
bool repeat = true;
while (repeat = true)
{
cout << "Please select an option." << endl;
cout << "[1] Continue Program" << endl;
cout << "[0] Terminate Program" << endl;
cout << "---------------------" << endl;
repeat = false;
cin >> num;
cout << endl;
if (num = 1)
{
repeat = true;
//execute program
}
else if (num = 0)
repeat = false;
else
cout << "Please enter an appropriate value.";
}
return 0;
}
當您使用調試器逐行執行程序時,您發現了什麼? – 2014-09-25 02:23:07