永发信息网

这段C++程序哪里错了?newline in constants yntax error : missing ';' before identifier 'cin&apo

答案:2  悬赏:0  手机版
解决时间 2021-04-16 02:34
  • 提问者网友:寂寞梧桐
  • 2021-04-15 10:31

#include <iostream>
using namespace std;
void main()
{
int n,k,l;
int i=1,j=6;
int a[5]={0,0,0,0,0};
int b[5]={0,0,0,0,0};
loop0:cout<<"Please type 1 for First Class "<<endl;
cout<<"Please type 2 for Economy "<<endl;
cin>>n;
if (n==1){
loop1:if(i<=5){
cout<<"First Class. Your number is "<<i<<endl;
i=i+1;
}
else {
cout<<"First Class is full. Do you want Economy Seat? Please type 1 for YES,type 2 for NO<<endl;
cin>>k;
if(k==1){
if(j>10){cout<<"Sorry, Economy Seat is full too. Next flight leaves in 3 hours."<<endl;}
else {goto loop2;}
}
if(k==2){cout<<"Next flight leaves in 3 hours."<<endl;}
}

if(n==2){
loop2:if(j<=10){cout<<"Economy. Your number is "<<j<<endl;
j=j+1;}
else {
cout<<"Economy is full. Do you want First Class Seat? Please type 1 for YES, type 2 for NO<<endl;
cin>>l;
if(l==1){
if(k>5){cout<<"Sorry, Economy Seat is full too. Next flight leaves in 3 hours."<<endl;}
else {goto loop1;}
}
if(l==2){cout<<"Next flight leaves in 3 hours."<<endl;}
}
}
if(i<=4||j<=9)goto loop0;
}

编译后显示错误:
\VC++6.0\VisualC++6.0简体中文绿色版\Microsoft Visual Studio\Common\MSDev98\Bin\Cpp1.cpp(18) : error C2001: newline in constant
D:\VC++6.0\VisualC++6.0简体中文绿色版\Microsoft Visual Studio\Common\MSDev98\Bin\Cpp1.cpp(19) : error C2146: syntax error : missing ';' before identifier 'cin'
D:\VC++6.0\VisualC++6.0简体中文绿色版\Microsoft Visual Studio\Common\MSDev98\Bin\Cpp1.cpp(31) : error C2001: newline in constant
D:\VC++6.0\VisualC++6.0简体中文绿色版\Microsoft Visual Studio\Common\MSDev98\Bin\Cpp1.cpp(32) : error C2146: syntax error : missing ';' before identifier 'cin'
D:\VC++6.0\VisualC++6.0简体中文绿色版\Microsoft Visual Studio\Common\MSDev98\Bin\Cpp1.cpp(45) : fatal error C1004: unexpected end of file found

最佳答案
  • 五星知识达人网友:由着我着迷
  • 2021-04-15 11:45
#include <iostream>
using namespace std;
main()
{
int n,k,l;
int i=1,j=6;
int a[5]={0,0,0,0,0};
int b[5]={0,0,0,0,0};
loop0:cout<<"Please type 1 for First Class "<<endl;
cout<<"Please type 2 for Economy "<<endl;
cin>>n;
if (n==1){
loop1:if(i<=5){
cout<<"First Class. Your number is "<<i<<endl;
i=i+1;
}
else {
cout<<"First Class is full. Do you want Economy Seat? Please type 1 for YES,type 2 for NO"<<endl;// 加双引号
cin>>k;
if(k==1){
if(j>10){cout<<"Sorry, Economy Seat is full too. Next flight leaves in 3 hours."<<endl;}
else {goto loop2;}
}
if(k==2){cout<<"Next flight leaves in 3 hours."<<endl;}
}

if(n==2){
loop2:if(j<=10){cout<<"Economy. Your number is "<<j<<endl;
j=j+1;}
else {
cout<<"Economy is full. Do you want First Class Seat? Please type 1 for YES, type 2 for NO"<<endl; // 加双引号
cin>>l;
if(l==1){
if(k>5){cout<<"Sorry, Economy Seat is full too. Next flight leaves in 3 hours."<<endl;}
else {goto loop1;}
}
if(l==2){cout<<"Next flight leaves in 3 hours."<<endl;}
}
}
if(i<=4||j<=9)goto loop0;
}
} // 漏了个大括号

这样改就可以编译通过了
望采纳
全部回答
  • 1楼网友:鸠书
  • 2021-04-15 12:06

cout<<"Economy is full. Do you want First Class Seat? Please type 1 for YES, type 2 for NO"<<endl;

少了个 "

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯