电影院规定,零售票价30元每张,20张及以上属于团体票,25元每张。编程,输入购票数量,计算总票价并输出。

电影院规定,零售票价30元每张,20张及以上属于团体票,25元每张。编程,输入购票数量,计算总票价并输出。

#include <stdio.h>

int main() {
    int amount;
    float price;

    printf("请输入购票数量:");
    scanf("%d", &amount);

    if (amount >= 20) {
        price = amount * 25.0;
    } else {
        price = amount * 30.0;
    }

    printf("总票价为:%.2f 元\n", price);

    return 0;
}

img


#include <stdio.h>

int main()
{
    // 定义零售票价和团体票价
    int retail_price = 30;
    int group_price = 25;

    // 输入购票数量
    int num_tickets;
    printf("请输入购票数量:");
    scanf("%d", &num_tickets);

    // 计算总票价
    int total_price;
    if (num_tickets >= 20)
        total_price = num_tickets * group_price;
    else
        total_price = num_tickets * retail_price;

    // 输出总票价
    printf("总票价为:%d\n", total_price);

    return 0;
}
不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^