的錯誤是,當我運行該程序,並鍵入n
結束選擇 它並沒有結束,並不斷重複第一cout
,默認值爲:做一段時間,開關故障
#include <iostream>
using namespace std;
int main()
{
int x;
float y,result=0,paid,change;
do {
cout<<"enter another choose or press (n/N) to end choosing ";
cin>>x;
switch (x)
{
case 1:
{
int a=5;
cout<<"enter the wighte you want in (Kg) : ";
cin>>y;
result=a*y;
break;}
default:
cout<<"wrong choooose "<<endl;
}
}
while (x='n');
cout<<"your total= "<<result<<endl;
cout<<"mony value paid = ";
cin>>paid;
change =paid-result;
cout<<"the change = "<<change<<endl;
return 0;
}
如果你想n結束它,你忘了! (假設你打算把它變成一個角色,因爲這就是你正在閱讀的內容)。您還輸出n和N都是有效的,但想象一下當N不工作時用戶的困惑! – chris
ive添加了!但它也沒有工作,忘了N I只想用n個 –