#include<stdio.h>
#include<stdbool.h>
#define ARTICHOKE 2.05
#define BEET 1.15
#define CARROT 1.09
int main()
{
bool door = true;
char ch;
double art_num = 0.0;
double beet_num = 0.0;
double carrot_num = 0.0;
double total_price;
double total_weight;
double packing_freight;
int discount = 0;
while (door)
{
double count = 0.0;
printf("請輸入你要訂購的物品,訂購代碼 a(洋薊) , b(甜菜) , c(胡蘿卜),q(退出)\n");
scanf("\n%c", &ch);
switch (ch)
{
case 'a':
printf("您需要多少磅洋薊?");
scanf("%lf", &count);
art_num += count;
break;
case 'b':
printf("您需要多少磅甜菜?");
scanf("%lf", &count);
beet_num += count;
break;
case 'c':
printf("您需要多少磅胡蘿卜?");
scanf("%lf", &count);
carrot_num += count;
break;
case 'q':
door = false;
break;
}
}
total_price = art_num * ARTICHOKE + beet_num * BEET + carrot_num * CARROT;
total_weight = art_num + beet_num + carrot_num;
if (total_price >= 100.0)
{
discount = (int)total_price / 100.0 * 5;
total_price = total_price - total_price / 100 * (total_price * 0.05);
}
if (total_weight > 0.1 && total_weight < 5.0)
{
packing_freight = 6.5;
}
else if (total_weight > 5.0 && total_weight < 20.0)
{
packing_freight = 14.0;
}
else
{
packing_freight = 14.0 + (total_weight - 20.0) * 0.5;
}
printf("************************************************************\n");
printf("其中洋薊:%20.2lf磅\t花費:%15.2lf $\n", art_num, art_num * ARTICHOKE);
printf("其中甜菜:%20.2lf磅\t花費:%15.2lf $\n", beet_num, beet_num * BEET);
printf("其中胡蘿卜:%18.2lf磅\t花費:%15.2lf $\n", carrot_num, carrot_num * CARROT);
printf("其中包裝及運費:%14.2lf $\t折扣:%13d%%\n", packing_freight, discount);
printf("貨物總價:%20.2lf $\t貨物總重量:%9.2lf\n", total_price, total_weight);
printf("************************************************************\n");
return 0;
}
uj5u.com熱心網友回復:
#include<stdio.h>
#include<stdbool.h>
#define ARTICHOKE 2.05
#define BEET 1.15
#define CARROT 1.09
int main()
{
bool door = true;
char ch;
double art_num = 0.0;
double beet_num = 0.0;
double carrot_num = 0.0;
double total_price;
double total_weight;
double packing_freight;
int discount = 0;
while (door)
{
double count = 0.0;
printf("請輸入你要訂購的物品,訂購代碼 a(洋薊) , b(甜菜) , c(胡蘿卜),q(退出)\n");
//scanf("\n%c", &ch);
scanf("%c", &ch);
switch (ch)
{
case 'a':
printf("您需要多少磅洋薊?");
scanf("%lf", &count);
art_num += count;
break;
case 'b':
printf("您需要多少磅甜菜?");
scanf("%lf", &count);
beet_num += count;
break;
case 'c':
printf("您需要多少磅胡蘿卜?");
scanf("%lf", &count);
carrot_num += count;
break;
case 'q':
door = false;
break;
}
getchar();
}
total_price = art_num * ARTICHOKE + beet_num * BEET + carrot_num * CARROT;
total_weight = art_num + beet_num + carrot_num;
if (total_price >= 100.0)
{
discount = (int)total_price / 100.0 * 5;
total_price = total_price - total_price / 100 * (total_price * 0.05);
}
if (total_weight > 0.1 && total_weight < 5.0)
{
packing_freight = 6.5;
}
else if (total_weight > 5.0 && total_weight < 20.0)
{
packing_freight = 14.0;
}
else
{
packing_freight = 14.0 + (total_weight - 20.0) * 0.5;
}
printf("************************************************************\n");
printf("其中洋薊:%20.2lf磅\t花費:%15.2lf $\n", art_num, art_num * ARTICHOKE);
printf("其中甜菜:%20.2lf磅\t花費:%15.2lf $\n", beet_num, beet_num * BEET);
printf("其中胡蘿卜:%18.2lf磅\t花費:%15.2lf $\n", carrot_num, carrot_num * CARROT);
printf("其中包裝及運費:%14.2lf $\t折扣:%13d%%\n", packing_freight, discount);
printf("貨物總價:%20.2lf $\t貨物總重量:%9.2lf\n", total_price, total_weight);
printf("************************************************************\n");
return 0;
}
供參考~
uj5u.com熱心網友回復:
GitHub FYIuj5u.com熱心網友回復:
準備學習C啦。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/11087.html
標籤:新手樂園
