【问题标题】:Id returned 1 exit status. C++Id 返回 1 个退出状态。 C++
【发布时间】:2017-04-02 09:43:57
【问题描述】:

我对 C++ 很陌生,所以我可能犯了一些非常愚蠢的错误。但是我已经在网上查看了此错误的解决方案,并且我尝试了所有我能想到的。

我试图将我的整个程序放在一个函数中,因为它将与其他程序合并。 id 错误是我目前唯一的错误。

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

using namespace std;
int ninebooking(int Endor=0, int Naboo=0, int tatooine=0);
int sevenbooking(int Endor=0, int Naboo=0, int tatooine=0);
void BookingSystem(int time, int k);
int time;
int k = 0;

int main() 
{
BookingSystem(time, k);
{
while (k==0)
{
printf("\n\nMeals are served at 9pm and 7pm, please enter what time you would like to book for");
scanf("You have selected to book your meal for %d", &time);
if (time!=7||time!=9)
{
        printf("Sorry, that was an incorrect time");
        time = 0;
}
}
return 0;
}

system ("pause");
return 0;
}

非常感谢任何帮助,我花了很长时间试图自己解决这个问题,但没有运气。

谢谢!

【问题讨论】:

  • time!=7||time!=9 再次...除非time 是一个类并且您对其进行了一些有趣的运算符重载,否则这是没有意义的。
  • @LogicStuff 他们在第一学期永远不会得到那个。
  • 您写道:我试图将我的整个程序放在一个函数中,因为它将与其他程序合并。就目前而言,这没有任何意义,你能详细说明一下吗?
  • @Toby 提示:(time != 7 || time != 9) 总是正确的。
  • main 中的这段代码可能是函数Bookingsystem 的定义吗?如果是这种情况,那么不,它不是函数的定义。 BookingSystem(time, k); 调用函数(未在任何地方定义),然后跟随一些代码块

标签: c++ function void dev-c++


【解决方案1】:

你在程序中犯了很多错误:

1) 你混合了 C 和 C++ 语法。

使用命名空间std,是C++

2) 你包含了无用的头文件

3) 你声明了我不明白的变量

为什么需要这个?

int Ninebooking(int Endor=0, int Naboo=0, int tatooine=0);
int Sevenbooking(int Endor=0, int Naboo=0, int tatooine=0);

你不要在任何地方使用上面的变量!!!!

4) 您尝​​试在 inside main 中编写一个函数(这不是 Pascal)。

所以,如果我明白你想要什么,看看这个:

#include <stdio.h>

void BookingSystem() // this is the function who does all job
{
    int time = 0;

    while ((time != 7) && (time != 9))
    {
        printf("\n\nMeals are served at 9pm and 7pm, please enter what time you would like to book for");
        printf("\nYou have selected to book your meal for ");
        scanf("%d", &time); // read the time
        scanf("%*[^\n]");   // consume all caracters until the newline
        scanf("%*c");       // consume the newline
        if (time == 7)
        {
            printf("You have selected to book your slot at 7PM\n");
        }
        else if (time == 9)
        {
            printf("You have selected to book your slot at 9PM\n");
        }
        else
        {
            printf("You have selected an incorrect time, please try again\n");
        }

    } // end while
} // end function


int main(int argc, char *argv[])
{
    BookingSystem(); // this is the calling to your function

    return 0;
}

如果我了解您想要什么,这可以正常工作。

【讨论】:

    【解决方案2】:

    你不能在 main 中定义函数.. 你必须这样做......

    #include<stdio.h>
    #include<stdlib.h>
    #include<ctype.h>
    #include<string.h>
    
    using namespace std;
    
    int ninebooking(int , int , int );  //just say data type int or ....
    int sevenbooking(int , int , int );
    void BookingSystem(int , int);
    
    int main() //and in to main just call he...
    {
     int time;
     int k = 0;
    
     BookingSystem(time, k);//call ....and send parameter time and k
    
     system ("PAUSE");
     return 0;
    
    }
    
    void BookingSystem(int time,int k)
    {
        while (k==0)
        {
            printf("\n\nMeals are served at 9pm and 7pm, please enter what time you would like to book for");
            scanf("You have selected to book your meal for %d", &time);
            if (time!=7||time!=9)
            {
                printf("Sorry, that was an incorrect time");
                time = 0;
            }
        }
        //  return 0;//if this function is void he can not to return any thing!!!!
    }
    
    int ninebooking(int Endor=0, int Naboo=0, int tatooine=0)
    {
        //......
    }
    
    int sevenbooking(int Endor=0, int Naboo=0, int tatooine=0)
    {
        //........
    }
    

    【讨论】:

      猜你喜欢
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 2013-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-26
      • 1970-01-01
      相关资源
      最近更新 更多