代码值应该每次都改变,所以相同的座位不显示,但它没有
Code value is supposed to change every time so the same seat does not display but it doesn’t
//
// 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
,在那之后的行…如果你的编译器没有警告你,那么试着调高它的警告级别。
相关文章:
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 我是 c++ 的新手.学习基本知识后,我想做井字游戏.对于印刷板,我在下面写代码,但它显示错误
- Clion显示错误,但可以使用Cmake成功构建代码
- 代码使用向量成功运行,但使用数组显示错误
- 这两个代码片段相似,但显示的结果不同
- 与clang++一起使用的VS代码在构建良好的C++文件中显示错误
- 代码未在联机编译器上显示结果
- 程序显示以退出代码 0; 结束
- 任何人都可以弄清楚这段代码如何显示运行错误?它打印无限时间 -1 以及正确答案
- 为什么我的代码块上没有显示输出?
- Qt GUI使用Qfiledialogbox和qlabel显示视频,这是我的代码
- 执行此代码时,它不显示任何输出.为什么?
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- 为什么此代码中显示"*** stack smashing detected ***: <unknown> terminated Aborted (core dumped) "错误?
- objdump 不显示机器代码,但显示 ASM
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- 为什么当我在 c++ 中运行函数时,我的代码显示数字 53
- 我只是在寻找模板,在我的书中找到了这段代码,这显示了隔离错误?
- 我的代码厨师提交显示错误的结果
- 删除矢量显示代码 c++ 段时答案更改