首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >一个简单的C++程序

一个简单的C++程序
EN

Stack Overflow用户
提问于 2011-04-13 18:33:28
回答 4查看 289关注 0票数 0
代码语言:javascript
运行
复制
#include<iostream>
using namespace std;
int main()
{
char res[13][6];
int i,j;
int choices=0;

// Declaration of all the variable.
int row0,row1=0,row2=0,row7,row8;
int class_choices=0;

for(i=0;i<13;i++)
    for(j=0;j<6;j++)
        res[i][j]='*';

do
{
    cout<<"Type of service provided. "<<endl;
    cout<<"1. To enter your ticket type."<<endl;
    cout<<"2. To display full reservation status."<<endl;
    cout<<"3. Exit."<<endl<<endl;
    cout<<"Enter your choice : ";
    cin>>choices;
    switch(choices)
    {
        // Type of class provided.
        case 1:
            cout<<endl<<"1. First Class"<<endl;
            cout<<"2. Economy Class"<<endl;
            cout<<"Enter your choice : ";
            cin>>class_choices;
            switch(class_choices)
            {
                // First Class.
                case 1:
                    cout<<endl<<"Class specified by you : First Class";
                    row1=0;
                    row2=1;
                    break;

                // Economy Class.
                case 2:
                    cout<<endl<<"Class specified by you : Economy Class";
                    row0;
                    row1=2;
                    row2=12;
                    row7;
                    row8;
                    break;
                // To indicate the user made a wrong choice.
                default:
                    cout<<"WRONG CHOICE";
                    break;
            }
            // To indicate that "*" is available seats and "X" is occupied seats.
            cout<<endl<<"* - Available Seats";
            cout<<endl<<"X - Occupied Seats";
            cout<<endl<<"Available seats for you are :: "<<endl;
            cout<<"\t"<<"A  B   C   D   E   F"<<endl;
            for(i=row1;i<=row2;i++)
            {
                cout<<"Row "<<i+1;
                for(j=0;j<6;j++)
                {
                    cout<<"\t"<<res[i][j];
                }
                cout<<endl;
            }

            int seat_row;
            cout<<endl<<"Enter your desired row : Row ";
            cin>>seat_row;

            // Condition for the non-smoking section.
            if (seat_row>row0 && seat_row<row8)
            {
                int row0,row8;
                cout<<"For your information, these are non-smoking section."<<endl;

            }

            // Condition for the smoking section.
            else  (seat_row>row7);
            {
                int row7;
                cout<<"For your information, these are smoking section."<<endl; 
            }

            if(seat_row<(row1+1) || seat_row>(row2+1))
            {
                cout<<"Invalid row selected";
                system("pause");
                break;
            }


            int seat;
            cout<<endl<<"Enter your desired seat number (1-6) :";
            cin>>seat;
            if(seat<1 || seat>6)
            {
                cout<<"Invalid seat selected";
              system("pause");
                break;
            }

            if(res[seat_row-1][seat-1]!='X')
            {
                res[seat_row-1][seat-1]='X';
                cout<<endl<<"Reserved";
            }
            else
            {
                cout<<endl<<" Owh,no! ! ! This seat is taken.";
                break;
            }
            system("pause");
            break;

            // To display reservation status.
        case 2:
            cout<<endl<<"\tA    B   C   D   E   F"<<endl;
            for(i=0;i<13;i++)
            {
                cout<<"Row "<<i+1;
                for(j=0;j<6;j++)
                {
                    cout<<"\t"<<res[i][j];
                }
                cout<<endl;
            }


            system("pause");

            // To exit.
        case 3:
            break;
        }
}
while(choices!=3);
        return 0;


}

我的错误是错误C2143:语法错误:缺少';‘位于以下位置的'{’之前: else (seat_row>row7);{ int row7;cout<<“供您参考,这些是冒烟部分<

EN

回答 4

Stack Overflow用户

发布于 2011-04-13 18:38:19

else语句不能有条件,即使有,也不会在语句的末尾加分号。使用这个

代码语言:javascript
运行
复制
...
}
else if(seat_row>row7)
{
    ...
}

希望这能有所帮助。

票数 3
EN

Stack Overflow用户

发布于 2011-04-13 18:38:46

你说过:

代码语言:javascript
运行
复制
else  (seat_row>row7);
    {

我想你的意思是:

代码语言:javascript
运行
复制
else if (seat_row > row7)
    {
票数 2
EN

Stack Overflow用户

发布于 2011-04-13 18:39:08

else (seat_row>row7);

应该是

else if (seat_row>row7)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5647744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档