预期声明和预期声明错误c ++

时间:2015-03-22 14:15:31

标签: c++

// Check the account number validity function
void chk_ac_num(string &ac_num, string a_num[], int cnt)
{
    // Declare variables
    int check=0;
    // Checking for 8 digit
    do
    {
        cout<<"Enter Desired Account Number (8 Digit):"<<endl;
        getline(cin, ac_num);
        check=ac_num.length();
        if(check==8)
        {
            for(int i=0;i<cnt;i++)
            {
                if(ac_num==a_num[i]) // Checking same account number existed or not
                {
                    check=1;
                    cout<<"Account Number already exist, please enter another desired number !"<<endl;  // Same account number detected
                    break;
                }
            }
        }
        else
            if(check==0)
                system("cls");
            else
                cout<<"Please enter 8 digit number !"<<endl;
    }while(check!=8); // Loop it when the account number is existed or not valid
}

我预计我的第二个语句会出现语句错误,并且在我的条件下也有预期的声明错误....我怎么能修复它们?

1 个答案:

答案 0 :(得分:0)

所以我在你的函数周围放了一些代码。

#include <iostream>
#include <stdlib.h>

using namespace std;

void chk_ac_num(string &ac_num, string a_num[], int cnt)
{
    // Declare variables
    int check=0;
    // Checking for 8 digit
    do
    {
        cout<<"Enter Desired Account Number (8 Digit):"<<endl;
        getline(cin, ac_num);
        check=ac_num.length();
        if(check==8)
        {
            for(int i=0;i<cnt;i++)
            {
                if(ac_num==a_num[i]) // Checking same account number existed or not
                {
                    check=1;
                    cout<<"Account Number already exist, please enter another desired number !"<<endl;  // Same account number detected
                    break;
                }                }
            }
        }
        else
            if(check==0)
                system("cls");
            else
                cout<<"Please enter 8 digit number !"<<endl;
    }while(check!=8); // Loop it when the account number is existed or not valid
}

int main()
{
string acnum = "12345678";
string acnumarray[4] = ("12345670", "23456679", "98764432", "56565656");
chk_ac_num(acnum, acnumarray, 4);

return 0;
}

它在g ++下编译好。我建议你在else块中使用花括号来防止意外行为,如果你决定将这些控制块扩展到多行一行。

编辑修复。 Parens!= Curly Brackets。

相关问题