2016-09-27 20 views
0

私はユーザーが '0'を入力するまで数字の入力を集めています。 また、ユーザーがループを終了することを決定すると、ユーザーは再開するかどうかを決定できます。 プログラムを修正するにはどうすればよいですか?あるいは、このプログラムをより効率的に送る別の方法がありますか?このループはどのように動作させるのですか?

`

int regular, special, vip; 
int i; 
bool flag = true; 

while(flag) 
{ 
    cout << "input please: "; 
    cin >> i; 

    if ((i <10000) && (i > 0)) 
    { 
     regular++; 
    } 

    if ((i >10000) && (i<=50000)) 
    { 
     special++; 
    } 

    if (i > 50000) 
    { 
     vip++; 
    } 

    if (i==0); 
    { 
     flag = false; 
     cout << "Your branch has " << regular << " Regular Customers, " 
      << special << " Special Customers and " << vip << " VIP Customers" 
     << "Try again? [1 = yes/ 0 = no] " << endl; 
    } 
} 

}`

+2

後にセミコロンを削除;' – paddy

+1

@paddy OnAncientJoke: '(incoming_detected(あれば) ); launch_nuclear_counterstrike(); ' –

+0

jfc私は盲目になりました! – asteron9

答えて

0

これは動作するはずです。 coutに設定してから、flagをfalseに設定してください。

も開始するには良い場所は、(i == 0)であれば、 `からセミコロンを削除することですif(i==0)

int regular, special, vip; 
int i; 
bool flag = true; 

while(flag) 
{ 
    cout << "input please: "; 
    cin >> i; 

    if ((i <10000) && (i > 0)) 
    { 
     regular++; 
    } 

    if ((i >10000) && (i<=50000)) 
    { 
     special++; 
    } 

    if (i > 50000) 
    { 
     vip++; 
    } 

    if (i==0) 
    { 
     cout << "Your branch has " << regular << " Regular Customers, " 
      << special << " Special Customers and " << vip << " VIP Customers" 
      << "Try again? [1 = yes/ 0 = no] " << endl; 
     flag = false; 
    } 
} 
0

私はあなたが正しく求めているものを理解していれば、あなただけもう一度試してみて、それに基づいて何かをするために、ユーザーの選択に読まなければなりません。ああ、また、セミコロンを後に削除するif(i==0)

if (i==0) 
{ 
    flag = false; 
    cout << "Your branch has " << regular << " Regular Customers, " 
     << special << " Special Customers and " << vip << " VIP Customers" 
    << "Try again? [1 = yes/ 0 = no] " << endl; 

    /* Do what the user wants */ 
    cin>> i; 
    if(i == 1) 
    { 
     /* Reset regular, special, and vip variables if desired */ 

     flag = true; 
    } 
} 
関連する問題