ID 返回 1 退出状态。 C++

Id returned 1 exit status. C++

我是 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;
}

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

谢谢!

你的程序有很多错误:

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;
}

如果我明白你想要什么,这很好用。

你不能在主程序中定义函数.. 你必须这样做...

#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)
{
    //........
}