预期语句和预期声明错误 c++
Expected statement and expected declaration error 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
}
我在第二个其他情况下预期了语句错误,在我的while条件下也有预期的声明错误......我该如何修复它们?
所以我在你的函数周围放了一些代码。
#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 块中使用大括号以防止意外行为,如果您决定将这些控制块扩展到超过一行长。
编辑以修复。括号 != 大括号。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'