代码值应该每次都改变,所以相同的座位不显示,但它没有

Code value is supposed to change every time so the same seat does not display but it doesn’t

本文关键字:显示 代码 改变      更新时间:2023-10-16
//
//  main.cpp
//  airline ticket
//
//  Created by has on 5/1/14.
//  Copyright (c) 2014 has. All rights reserved.
//
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

这部分是函数函数不保留其值,也不返回

int place(int plane[],int count){
    int seat = 0;
    seat = count+1;
    plane[count]=1;
    return seat;
}

这是它开始的地方这与保持前一个售出座位的值为1并给出下一个座位的编号

相反。
int main(int argc, const char * argv[])
{
    int count; int plane[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, seat;
    for (count=0; count < 20; count++)
    {
        if(plane[count] == 0)
        {
            place(&plane[count], count);
            cout<< " this is your seat number for the flight "<< seat<<endl;
            return 0;
        }
        if(plane[19]!=0)
        {
            cout<< " the first calss seats are all booked, we may have secondary class avabile would like to try"<<endl;
        }
    }
        return 0;
}

您忘记使用返回值了。变化:

place(&plane[count], count);

seat = place(&plane[count], count);

一些编译器会给出一个警告,你使用了未初始化的seat,在那之后的行…如果你的编译器没有警告你,那么试着调高它的警告级别。