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

时间:2016-11-18 13:51:38

标签: c++ function void dev-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;
}

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

谢谢!

2 个答案:

答案 0 :(得分:0)

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

1)你混合C&amp; 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)你试着写一个里面的函数 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;
}

如果我理解你想要的东西,这很好用。

答案 1 :(得分: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)
{
    //........
}