C (儿童); 总计=(成人*padult)+(儿童*PKID); printf(“选择座位:\n”); 浮动座椅(); printf(“总计=RM.2%f\n”,总计); 返回总数; }

C (儿童); 总计=(成人*padult)+(儿童*PKID); printf(“选择座位:\n”); 浮动座椅(); printf(“总计=RM.2%f\n”,总计); 返回总数; },c,arrays,switch-statement,C,Arrays,Switch Statement,您的代码中有许多问题。举几个例子: scanf(“%c”和&choice1)将考虑回车键。 案例5浮动价格()-->不正确 if(decision1=='y'){main();}-->使用标志和do..while() 等等等等 而且,把所有的东西都放在主管道里也不是一个很好的练习。要清理代码并增强可读性,如何为每个案例创建单独的函数,并从开关案例中调用它们?自己调试代码。糟糕的编码!!。函数调用应该是price()非浮动价格()。不要从main调用main。我认为您不熟悉不要从代码中递归调用ma

您的代码中有许多问题。举几个例子:

  • scanf(“%c”和&choice1)将考虑回车键。

  • 案例5<代码>浮动价格()-->不正确

  • if(decision1=='y'){main();}
    -->使用标志和
    do..while()

  • 等等等等


    而且,把所有的东西都放在主管道里也不是一个很好的练习。要清理代码并增强可读性,如何为每个
    案例创建单独的函数,并从
    开关
    案例中调用它们?

    自己调试代码。糟糕的编码!!。函数调用应该是
    price()
    浮动价格()。不要从main调用
    main
    。我认为您不熟悉不要从代码中递归调用
    main()
    ,为什么不呢?也许他想造成站点名称、堆栈溢出……你有太多
    中断,但还是忘了一个。@Gil.我啊,对了,错过了那个。。。顺便说一句,根据标准,这是未定义的行为:
    
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    
    void printarray(const int[6][10]);
    float price();
    float seat();
    int i,j;
    int array[50][50]={1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1,10,
                       2,1,2,2,2,3,2,4,2,5,2,6,2,7,2,8,2,9,2,10,
                       3,1,3,2,3,3,3,4,3,5,3,6,3,7,3,8,3,9,3,10,
                       4,1,4,2,4,3,4,4,4,5,4,6,4,7,4,8,4,9,4,10,
                       5,1,5,2,5,3,5,4,5,5,5,6,5,7,5,8,5,9,5,10,
                       6,1,6,2,6,3,6,4,6,5,6,6,6,7,6,8,6,9,6,10};
    
    float padult=12.00, pkids=8.00, total, adult, kids, tadult, tkids;
    char choice1, y, n;
    char decision1;
    char decision2;
    
    
    int main()
    {
        printf("\n\t\t\t WELCOME \n\t\t\t\t\tTO\n\t\t\t THE CINEMAS \n");
        printf("\n\t\t Please choose your movie: \n");
    
        int choice;
        printf("\n\t\t1. Finding Nemo ");
        printf("\n\t\t2. Transformers ");
        printf("\n\t\t3. Don't Break My Heart");
        printf("\n\t\t4. Meet The Robinson");
        printf("\n\t\t5. Good Night!!");
        printf("\n\t\t6. Cancel");
        printf(" \n\n\n Please choose 1 of the option: ");
        scanf("%d", &choice);
    
        switch(choice) {
        case 1:
            printf("\nTitle: Finding Nemo\n");
            printf("Description:\n");
            printf("About a fish name Nemo caught by a human. And his father tries to save him by travelling around the world. ");
            printf("\nNemo is being caught and  unconciously being brought to Sydney, Australia..." );
            printf("\nWill his father who never leave their home save Nemo... Will his father survive the travelling around the world.. ");
            printf("\nGenre: Cartoon\n");
            printf("Do you want to watch this movie:[y][n]\n");
            scanf("%c",&choice1);
            scanf("%c",&choice1);
    
            if(choice1 == 'y'){
                price();
                break;
            } else {
                main();
            }
            break;                
    
        case 2:
            printf("\nTitle: Transformers\n");
            printf("Description:\n");
            printf("Story starts when 5 robots that call themselves Autobots arrive on Earth. They tried to protect human from Decepticon which are evil.\nThey fought the Decepticon clan with all their might. Will the earth be saved by the Autobots...\nOr will the Earth fall to the hand of the Decepticon and human race extinct...");
            printf("\nGenre: Scifi\n");
            printf("Do you want to watch this movie:[y][n]\n");
            scanf("%c",&choice1);
            scanf("%c",&choice1);
    
            if(choice1 == 'y'){
                float price();
                break;
            } else {
                main();
            }
            break;
    
    
        case 3:
            printf("\nTitle: Don't Break My Heart...\n ");
            printf("Description:\n");
            printf("Don't Break My Heart is a story about a young girl named Elizabeth that doesn't believe in love anymore. At the age of 16, she's being played by the most handsome boy in her school.\nThe boy broke up with her in front of the school assembly making her embarrased to go to school after that situation. Luckily, a boy named Samuel like her but never reveal his true feelings.\nHe than help the girl to realise the happiness of love. Will the girl realise the true feelings of Samuel...");
            printf("\nGenre: Romance\n");
            printf("Do you want to watch this movie:[y][n]\n");
            scanf("%c",&choice1);
            scanf("%c",&choice1);
    
            if(choice1 == 'y'){
                float price();
                break;
            } else {
                main();
            }
            break;
    
    
        case 4:
            printf("\nTitle: Meet The Robinson\n");
            printf("Description:\n");
            printf("Meet The Robinson is a Disney cartoon that tells us about a lonely orphan is being attacked by his enemy from the future. He is than help by his own son from the future.\nHe has to help his son so his enemy does not change the past. He help his son defeat his true enemy by time travelling.\nHis enemy who's actually his childhood friend realise that he is being used. He then switches sides and defeated their true enemy.\nThis movie shows you how friendship help us defeat anything eventhough they are far away.");
            printf("\nGenre: Cartoon\n");
            printf("Do you want to watch this movie:[y][n]\n");
            scanf("%c",&choice1);
            scanf("%c",&choice1);
    
            if(choice1 == 'y'){
                float price();
                break;
            } else {
                main();
            }
            break;
    
    
        case 5:
            printf("\nTitle: Good Night!!\n");
            printf("Description:\n");
            printf("Good Night!! is a horror story about a ghost who live in peoples dream. Once he entered the dream, it will come out until the dreamer died.\nYou cannot get out of the dream unless you are awake before the final sign. If you get to see this ghost what will you do?\nFind out how they defeat the ghost inside the dream..");
            printf("\nGenre: Horror\n");
            printf("Do you want to watch this movie:[y][n]\n");
            scanf("%c",&choice1);
            scanf("%c",&choice1);
    
            if(choice1 == 'y'){
                float price();
                break;
            } else {
                main();
            }
            break;
    
    
        case 6:
            printf("\nThank you!!\nGood bye\n");
    
    
        default:
            printf("Invalid choice...\n");
            printf("\n\n Do you wish to continue?[y][n]: ");
            scanf("%c", &decision1);
    
            if(decision1 == 'y'){
                main();
            } else {
                printf("\n\n Thank You!!\nGood bye\n");
                break;
            }
            break;
        }             
        system("pause");
        return 0;
    }
    
    
    float price(){
          printf("\n\tPrice:  Adult: RM12.00\n\tChildren: RM8.00\n");
          printf("How many adult: \n");
          scanf("%d", &adult);
          printf("How many kids: \n");
          scanf("%d", &kids);
          printf("You have %d adult and %d kids\n", adult, kids);
          total=(adult*padult)+(kids*pkids);
          printf("Select seats: \n");
          float seats();
          printf("Total= RM .2%f\n", total);
          return total;
    }