你可以請修復這個程序。它不會z。爲什麼不是我的聲明工作
int main()
{
using namespace std;
int x, y, z, a;
cout << "Please enter a number" << endl;
cin >> x;
cout << "Please enter another number" << endl;
cin >> y;
cout << "What do you want to do with these numbers?" << endl;
cout << "1 = +" << endl;
cout << "2 = -" << endl;
cout << "3 = *" << endl;
cout << "4 = /" << endl;
cin >> a;
do {
z = add(x, y);
} while (a == 1);
do {
z = sub(x, y);
} while (a == 2);
do {
z = mul(x, y);
} while (a == 3);
do {
z = dis(x, y);
} while (a == 4);
cout << z;
return 0;
}
我試過使用do while語句,但是我無法讓它工作。 ---編輯--- 添加了正確的縮進,爲什麼不自動這樣做?
u可以使用wwitch – PSR 2013-03-02 10:04:32
@PSR咦?我不明白。請提供更多細節。 – Lemonizer 2013-03-02 10:06:06
您的循環不會修改'a'。所以如果它進入一個循環,它將永遠不會出去。 – Barmar 2013-03-02 10:06:19