为什么我的账单计算功能不起作用?

Why is my bill calculation function won't work?

我正在做一个酒店管理系统的程序,但是在为客户计算账单时发现了一个问题。 这是我的代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<conio.h>

//Declaration

//Struct for the customers
struct Identity
{
    char name_first[50];
    char name_last[50];
    int phone;
    int IC[10];
    char email[50];
    int age;
};
struct Date
{
    int day;
    int month;
    int year;
};
struct Customer
{
    struct Identity iden;
    int room_number;
    int *room_type;
    int bill;
    struct Date check_in;
    struct Date check_out;
    int day_num;
    int cleaning;
};

//Function to count the check out and check in date for customer
//and also for billing
const int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int countLeapYear(struct Date d)
{
    int years = d.year;

    if(d.month <= 2)
    {
        years--;
    }

    return years / 4 - years / 100 + years / 400;
}

int getDays(struct Date d1, struct Date d2)
{
    long int n1 = d1.year * 365 + d1.day;

    for(int i = 0; i < d1.month - 1; i++)
    {
        n1 += monthDays[i];
    }
    n1 += countLeapYear(d1);

    long int n2 = d2.year * 365 + d2.day;
    for(int i = 0; i < d2.month - 1; i++)
    {
        n2 += monthDays[i];
    }
    n2 += countLeapYear(d2);
    return (n2 - n1);
}

//Function to count the bill of the customers room
int getBill(int days, int type, int num_of_room)
{
    int t = type;
    if(t = 1)
    {
        printf("\n200\n");
        return 200 * days * num_of_room;
    }
    else if(t = 2)
    {
        printf("500\n");
        return 500 * days * num_of_room;
    }
    else if(t = 3)
    {
        printf("1200\n");
        return 1200 * days * num_of_room;
    }
    else 
    {
        return 0;
    }

}

int main()
{
    int n = 0;
    printf("Input number of customers:\n");
    scanf("%d", &n);
    struct Customer cust[n];
    int num_of_room = 0;
    printf("\n***Please choose your room type***\n");
    printf("How many room do you want?\n");
    scanf("%d", &num_of_room);
    printf("Which type of room do you want?\n");
    printf("1.Standard Room (0/night)\n");
    printf("2.Deluxe Room (0/night)\n");
    printf("3.Ocean view room (00/night\n");
    printf("Input the type of room number (1,2,3):\n");
    scanf("%d", &cust->room_type);
    int type = cust->room_type;
    printf("***Please Confirm The Length of Your Stay***\n");
    printf("Input check-in date (DD,MM,YYYY):\n");
    scanf("%d,%d,%d", &cust->check_in.day, &cust->check_in.month, &cust->check_in.year);
    printf("\nInput check-out date (DD,MM,YYYY):\n");
    scanf("%d,%d,%d", &cust->check_out.day, &cust->check_out.month, &cust->check_out.year);

    struct Date D1;
    struct Date D2;
    D1.day = cust->check_in.day;
    D1.month = cust->check_in.month;
    D1.year = cust->check_in.year;
    D2.day = cust->check_out.day;
    D2.month = cust->check_out.month;
    D2.year = cust->check_out.year;

    int days = getDays(D1, D2);
    printf("The total days you are staying is %d days, type of room %d, number of room %d", days, type, num_of_room);
    cust->bill = getBill(days, type, num_of_room);
    printf("\nYou need to pay for $%d", cust->bill);
}

调试了一下,发现是房型的问题。不管我选择什么房型,总是按第一间房计算,也就是200美金。 这是输出的图片:

getBill()函数正确计算天数和房间数,但不能计算我选择的房间类型。

改变

  if(t = 1)  //assignment
            // assigns a value 1 to `t` and thereby if (1) is true.
            // then, it always executes the block
                {
                    printf("\n200\n");
                    return 200 * days * num_of_room;
                }

   if(t == 1)  // comparison

同样,或者更好的是,使用 switch 语句。