不输入我的人名功能。我放置函数和所有内容的方式在逻辑上是正确的吗?

问题描述 投票:0回答:1

我不知道为什么它不运行我的用户名功能。是我的编译器的错误还是我的编码的错误。如果我想放置指针,我应该把它放在哪里。并且,是否可以将指针 var 从主函数传递到其他函数?

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

void personname(int, char );
float totalprice1(int, float, float);

int main()
{
    float total1, ticketprice,alacarteprice, price, combo_price=0, 
    drink_price=0, popcorn_price=0, snacks_price=0, comboset=0, 
    totalprice=0;
    int  pay, snacks, popcorn, beverage, order, set, menu, food, i,booking, 
    time, movie, people=0, number=0, quantity=0, qtyBev=0, qtyPopcorn=0, 
    qtySnacks=0, alacarte=0;
    char date[50], people1[100][100];

    printf ("Choose your movie (1=BabyBoss   2=GuardiansOFTheGalaxy  
    3=Fast&Furious8   4=ShockWave  5=BeautyandTheBeast  6=GetOut): ");
    scanf ("%d",&movie);

    puts ("Enter your date: ");
    scanf ("%s",&date);

    if (movie==1)
   {
       printf ("Choose Showing Time ( 1=9:00 a.m , 2=3:15 p.m, 3=5:00 p.m, 
       4=8:30 p.m): ");
       scanf ("%d",&time);

       switch (time)
    {
        case 1: price=12;
        break;

        case 2: price=12;
        break;

        case 3: price=14;
        break;

        default: printf ("Wrong input");
    }
}
else
if (movie==2)
{
    printf ("Choose Showing Time (1=12:00 p.m , 2=3:30 p.m , 3=8:00 p.m , 
    4=10:30 p.m): ");
    scanf ("%d",&time);

    switch (time)
    {
        case 1: price=15;
        break;

        case 2: price=15;
        break;

        case 3: price=17;
        break;

        case 4: price=17;
        break;

        default: printf ("Wrong input");
    }
}
else
if (movie==3)
{
    printf ("Choose Showing Time (1=2:00 p.m, 2=5:00 p.m , 3=8:00 p.m , 
    4=10:30 p.m): ");
    scanf ("%d",&time);

    switch (time)
    {
        case 1: price=16;
        break;

        case 2: price=16;
        break;

        case 3: price=18;
        break;

        case 4: price=18;
        break;

        default: printf ("Wrong input");
    }
}
else
if (movie==4)
{
    printf ("Choose Showing Time (1=2:00 p.m , 2=5:00 p.m , 3=8:00 p.m, 
    4=10:30 p.m): ");
    scanf ("%d",&time);

    switch (time)
    {
        case 1: price=16;
        break;

        case 2: price=16;
        break;

        case 3: price=18;
        break;

        case 4: price=18;
        break;

        default: printf ("Wrong input");
    }
}
else
if (movie==4)
{
    printf ("Choose Showing Time (1=2:00 p.m , 2=5:00 p.m , 3=8:00 p.m, 
    4=10:30 p.m): ");
    scanf ("%d",&time);

    switch (time)
    {
        case 1: price=16;
        break;

        case 2: price=16;
        break;

        case 3: price=18;
        break;

        case 4: price=18;
        break;

        default: printf ("Wrong input");
    }
}
else
if (movie==5)
{
    printf ("Choose Showing Time (1=11:00 a.m, 2=1:00 p.m , 3=3:30 p.m , 
    4=5:30 p.m , 5=9:30 p.m): ");
    scanf ("%d",&time);

    switch (time)
    {
        case 1: price=16;
        break;

        case 2: price=16;
        break;

        case 3: price=16;
        break;

        case 4: price=18;
        break;

        case 5: price=18;
        break;

        default: printf ("Wrong input");
    }

}
else
{
    printf ("Choose Showing Time ( 1=10:00 a.m, 2=1:00 p.m , 3=4:30 p.m , 
    4=6:00 p.m): ");
    scanf ("%d",&time);

    switch (time)
    {
        case 1: price=12;
        break;

        case 2: price=12;
        break;

        case 3: price=12;
        break;

        case 4: price=12;
        break;

        default: printf ("Wrong input");
    }

}

printf ("Do you want to proceed your bookings? (1 for Yes, 0 for No): ");
scanf ("%d",&booking);

if (booking==1)
{
    puts ("Enter number of person: ");
    scanf ("%d",&number);

    for (i=0;i<number; i++)
    {
        printf ("Enter your name: ");
        scanf ("%s",&people1[i]);
    }
}


printf ("\nTotal number of person: %d\n",number);


for (i=0; i<number; i++)
{
    personname (i, people1[i]);
}

printf ("\nDo you want to add-on cinema food? (1 for Yes, 0 for No): ");
scanf ("%d",&food);

if (food==1)
{
    do
    {
        printf ("Order Menu( 1=Combo set, 2=Alacarte, 3=cancel order food) : 
");
        scanf ("%d",&menu);

        if (menu==1)
        {
            printf (" Choose Your Choice (1=SetA[ 1caramel popcorn (S) + 1 
 softdrink (S) , 2=SetB [1 caramel popcorn(R) + 1 softdrink (R) , 3=SetC[1 
 caramel popcorn (L) + 2 softdrinks (R)):");
            scanf ("%d",&set);

            switch (set)
            {
                case 1: combo_price=7.8;
                break;

                case 2: combo_price=8.9;
                break;

                default: combo_price=11.9;
                break;
            }

            printf ("Quantity?:");
            scanf ("%d",&quantity);

            comboset=combo_price*quantity;
        }
        else
        if (menu==2)
        {
            printf ("Alacarte ( 1=Beverages,2=Popcorn, 3=Snacks)");
            scanf ("%d",&alacarte);

            if (alacarte==1)
            {
                printf (" Beverages(1=Softdrink, 2=Milo, 3=Nescafe, 
 4=Tropicana Juice): ");
                scanf ("%d",&beverage);

                switch (beverage)
                {
                    case 1: drink_price=3.6;
                    break;

                    case 2: drink_price=4.8;
                    break;

                    case 3: drink_price=3.4;
                    break;

                    default: drink_price=5.2;
                    break;
                }

                printf ("Quantity?: ");
                scanf ("%d",&qtyBev);
            }
            else
            if (alacarte==2)
            {
                printf ("Popcorn(1=Popcorn Caramel, 2=Lite 'N' Sweet, 
3=Salty): ");
                scanf ("%d",&popcorn);

                switch (popcorn)
                {
                    case 1: popcorn_price=5.2;
                    break;

                    case 2: popcorn_price=4.3;
                    break;

                    default: popcorn_price=4.7;
                    break;
                }

                printf ("Quantity?: ");
                scanf ("%d",&qtyPopcorn);
            }
        }
        else
            {
                printf ("Snacks (1=Chicken Nugget(6pcs), 2=Mashed potato, 
3=Curry puff(2pcs), 4=Kit-Kat): ");
                scanf ("%d",&snacks);

                switch (snacks)
                {
                    case 1: snacks=6.4;
                    break;

                    case 2: snacks=2.5;
                    break;

                    case 3: snacks=3.2;
                    break;

                    default: snacks=2.5;
                    break;
                }

                printf ("Quantity?: ");
                scanf ("%d",&qtySnacks);
            }

    alacarteprice=(drink_price*qtyBev)+(popcorn_price*qtyPopcorn)+
(snacks_price*qtySnacks);

    totalprice=comboset+alacarteprice;

    printf ("Are you done ordering food? (1 for Yes, 0 for No) : ");
    scanf ("%d",&order);

    }

    while (order==0);
}

ticketprice=price*number;

printf ("Do you want to make a payment?(1 for Yes, 0 for No) :");
scanf ("%d",&pay);

total1=totalprice1(pay, ticketprice, totalprice);

if (pay==1)
{
    printf ("Ticket Price: RM%.2f\n",ticketprice);
    printf ("Combo Set Price: RM%.2f\n",comboset);
    printf ("Alacarte Price: RM%.2f\n",alacarteprice);
}
else
{
    printf ("Order candelled\n");
    printf ("Ticket Price: RM0.00\n");
    printf ("Combo Set Price: RM0.00\n");
    printf ("Alacarte Price: RM0.00\n");
}

printf ("Total Price: %.2f",total1);

printf ("THANK YOU FOR CHOOSING OUR CINEMA >_< ");

return 0;
}

void personname(int a, char b)
   {
printf ("\nPerson %d: %s",a+1, b);
}

float totalprice1(int a, float b, float c)
{
float total;
total=b+c;

return total;
}

c arrays function pointers
1个回答
3
投票

如果要使用函数 personname 打印姓名,第二个参数必须是 char * 或 char[ ] 而不是 char。

示例:

void personname(int a, char *b)
{
    printf ("\nPerson %d: %s",a+1, b);
}
© www.soinside.com 2019 - 2024. All rights reserved.