如何使这个循环工作?

时间:2016-09-27 05:10:37

标签: c++ if-statement while-loop

我应该收集数字输入,直到用户输入'0'。 此外,一旦用户决定退出循环,用户可以决定是否再次开始。 我该如何修复我的程序?或者还有另一种方法可以更有效地提供这个程序吗?

`

 update S
 set SlsTypId = 'Here'
 from SVSLS S
 INNER join SVSLSOPS O on S.Slsid = O.SlsId
 WHERE O.SlsTypId  LIKE '%Here%'  
 AND O.SlsTypId  LIKE '%OnOrder%'

}`

2 个答案:

答案 0 :(得分: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;
    }
}

答案 1 :(得分:0)

这应该有效。在将cout设置为false之前flag

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;
    }
}