高階語言程式設計第四次作業

ajsn發表於2024-10-27

11.#include <stdio.h>

define ARTICHOKE_PRICE 2.05

define BEET_PRICE 1.15

define CARROT_PRICE 1.09

define DISCOUNT_THRESHOLD 100.0

define DISCOUNT_RATE 0.05

define SHIPPING_UNDER_5 6.5

define SHIPPING_5_TO_20 14.0

define SHIPPING_ABOVE_20 14.0

define SHIPPING_ABOVE_20_PER_POUND 0.5

int main() {
char choice;
float totalWeight = 0.0, totalCost = 0.0;

while (1) {
    printf("Enter a (artichokes), b (beets), c (carrots), q (quit): ");
    scanf(" %c", &choice);

    if (choice == 'q') break;

    float weight;
    printf("Enter weight in pounds: ");
    scanf("%f", &weight);
    totalWeight += weight;

    switch (choice) {
        case 'a':
            totalCost += weight * ARTICHOKE_PRICE;
            break;
        case 'b':
            totalCost += weight * BEET_PRICE;
            break;
        case 'c':

相關文章