运行这段程序发现有很多语法异常,不知道错哪了,帮忙指正一下
运行这段程序发现有很多语法错误,不知道哪里错了,帮忙指正一下。
#include<iostream>
using namespace std;
int main()
{
char ans;
const int max_hold = 60;
int person, rest_person;
do
{
if (max_hold >= person)
{
rest_person = max_hold - person;
cout << "该会议符合消防条例,合法。" <<endl;
cout << "该会议室还能容纳" << rest_person << "人。"<<endl;
}
else (max_hold < person)
{
cout << "该会议室违反消防条例,不合法。"<<endl;
}
cout << "要继续吗?请按Y或N. ";
cin >> ans;
}while (ans == 'Y' || ans == 'y');
return 0;
}
------解决方案--------------------
1、中文的()
2、else后跟条件
------解决方案--------------------
全角括号改成半角括号;person, rest_person最好先初始化;else后不能接条件语句。
------解决方案--------------------
int person, rest_person;变量赋值。
if (max_hold >= person)的小括号改成英文状态下的小括号。
else (max_hold < person)直接写else就行。
------解决方案--------------------
#include<iostream>
using namespace std;
int main()
{
char ans;
const int max_hold = 60;
int person, rest_person;
do
{
if (max_hold >= person)
{
rest_person = max_hold - person;
cout << "该会议符合消防条例,合法。" <<endl;
cout << "该会议室还能容纳" << rest_person << "人。"<<endl;
}
else (max_hold < person)
{
cout << "该会议室违反消防条例,不合法。"<<endl;
}
cout << "要继续吗?请按Y或N. ";
cin >> ans;
}while (ans == 'Y' || ans == 'y');
return 0;
}
------解决方案--------------------
1、中文的()
2、else后跟条件
------解决方案--------------------
全角括号改成半角括号;person, rest_person最好先初始化;else后不能接条件语句。
------解决方案--------------------
int person, rest_person;变量赋值。
if (max_hold >= person)的小括号改成英文状态下的小括号。
else (max_hold < person)直接写else就行。
------解决方案--------------------
#include<iostream>
using namespace std;
int main()
{
char ans;
const int max_hold = 60;
int person, rest_person;
do
{
if (max_hold >= person) //中文括号
{
rest_person = max_hold - person;
cout << "该会议符合消防条例,合法。" <<endl;
cout << "该会议室还能容纳" << rest_person << "人。"<<endl;
}
else //else后面怎么能有条件?
{
cout << "该会议室违反消防条例,不合法。"<<endl;
}
cout << "要继续吗?请按Y或N. ";
cin >> ans;
}
while (ans == 'Y'
------解决方案--------------------
ans == 'y');
return 0;
}