gpt4 book ai didi

c - 如何根据用户的输入计算账单?

转载 作者:行者123 更新时间:2023-11-30 20:38:37 24 4
gpt4 key购买 nike

我在根据消费者购买的东西计算电脑商店的账单时遇到了非常令人困惑的问题。可供选择的内容如下:

* The base package cost is $599 and includes 4 GB of memory,
a 512Gb Hard Drive and a 21" LED monitor.
Permitted upgrades to the base system add the following costs:
+ Upgrade to 8 GB or 12 GB of Memory adds $99 and $189 respectively.
+ Upgrade to 27" LED monitor adds $199.
+ Upgrade to a 128 GB SSD adds $119.
+ NO Video card upgrade possible for the base package.

* The professional package cost is $899 and includes 8 GB of memory,
a 1TB Hard Drive and a 27" LED monitor.
Permitted upgrades to the professional system add the following costs:
+ Upgrade to a maximum 16 GB of Memory adds $189.
+ Upgrade to 32" LED monitor adds $199.
+ Upgrade to a 256 or 512 GB SSD adds $189 and $399 respectively.
+ Upgrade to a discrete 2GB Video card adds $209.

* The game package cost is $1499 and includes 16 GB of memory,
a 256 SSD Drive, a 32" LED monitor, and a discrete 2 GB Video card.
Permitted upgrades to the game system add the following costs:
+ Upgrade to a maximum 32 GB of Memory adds $389
+ Upgrade to 28" 4K HD monitor adds $299
+ Upgrade to a 512 GB or 1 TB SSD adds $299 and $599 respectively.
+ Upgrade to a discrete 4GB Video card adds $399.

如果消费者在购买任何电脑后进行某些修改,我如何计算总体账单?

到目前为止我已经编写了以下程序,但似乎进展不顺利。

#include <stdio.h>
int main(){

int choice, addon1, addon2, addon3, addon4;
float price, stot, bpack, ppack, gpack;


printf("Welcome to the IPC Company's Computer System Calculator\n\n");
printf("Enter the package desired\n");
printf("(1: Basic, 2: Professional, 3: Game System) :");
scanf("%d", &choice);

if(choice == 1){

printf("\nEnter additional memory required\n");
printf("(o: 4 GB included, 1: 8 GB, 2: 12 GB) :");
scanf("%d", &addon1);
printf("\nEnter monitor required\n");
printf("(0: 21 inch LED included, 1: 27inch LED) :");
scanf("%d", &addon2);
printf("\nEnter Hard Drive required\n");
printf("(0: 512 GB already included, 1: 128 GB SSD) :");
scanf("%d", &addon3);

printf("\n================================\n");
printf("Basic Package: \t 599.00\n");
if(addon1 == 0)
printf("4 GB memory: \t 0.00\n");
if(addon1 == 1)
printf("8 GB Memory: \t 99.00\n");
if(addon1 == 2)
printf("12 GB Memory: \t 189\n");
if(addon2 == 0)
printf("21 inch LED monitor:\t 0.00\n");
if(addon2 == 1)
printf("27 inch LED monitor:\t 199.00\n");
if(addon3 == 0)
printf("512 GB Hard Drive: \t 0.00\n");
if(addon3 == 1)
printf("128 GB SSD: \t 119.00\n");

printf("================================\n");

stot = ;
printf("Sub Total: ", stot);


}
if(choice == 2){
printf("\nEnter additional memory required\n");
printf("(o: 8 GB included, 1: 16 GB) :");
scanf("%d", &addon1);
printf("\nEnter monitor required\n");
printf("(0: 27 inch LED included, 1: 32 inch LED) :");
scanf("%d", &addon2);
printf("\nEnter Hard Drive required\n");
printf("(0: 1TB Hard Drive, 1: 256 GB SSD, 2: 512 GB SSD) :");
scanf("%d", &addon3);
printf("\nEnter Video Card required\n");
printf("(0: 2 GB video card) :");
scanf("%d", &addon4);

printf("\n================================\n");
printf("Professional Package: \t 899.00\n");
if(addon1 == 0)
printf("8 GB memory: \t 0.00\n");
if(addon1 == 1)
printf("16 GB Memory: \t 189.00\n");
if(addon2 == 0)
printf("27 inch LED monitor:\t 0.00\n");
if(addon2 == 1)
printf("32 inch LED monitor:\t 199.00\n");
if(addon3 == 0)
printf("1TB GB Hard Drive: \t 0.00\n");
if(addon3 == 1)
printf("256 GB SSD: \t 189.00\n");
if(addon3 == 2)
printf("512 GB SSD: \t 399.00\n");
if(addon4 = 0)
printf("2 GB Discrete Video Card: \t 209.00");

printf("================================\n");

}
if(choice == 3){
printf("\nEnter additional memory required\n");
printf("(o: 16 GB included, 1: 32 GB) :");
scanf("%d", &addon1);
printf("\nEnter monitor required\n");
printf("(0: 32 inch LED included, 1: 28 inch 4K HD monitor) :");
scanf("%d", &addon2);
printf("\nEnter Hard Drive required\n");
printf("(0: 256 GB already included, 1: 1 TB SSD) :");
scanf("%d", &addon3);
printf("\nEnter Video Card required\n");
printf("(0: 2 GB video card included, 1: 4 GB video card) :");
scanf("%d", &addon4);

printf("\n================================\n");

printf("Game Package: \t 899.00\n");
if(addon1 == 0)
printf("16 GB memory: \t 0.00\n");
if(addon1 == 1)
printf("32 GB Memory: \t 389.00\n");
if(addon2 == 0)
printf("32 inch LED monitor:\t 0.00\n");
if(addon2 == 1)
printf("28 inch 4K HD monitor:\t 299.00\n");
if(addon3 == 0)
printf("256 GB SSD Drive: \t 0.00\n");
if(addon3 == 1)
printf("512 GB SSD: \t 299.00\n");
if(addon3 == 2)
printf("1TB SSD: \t 599.00\n");
if(addon4 = 0)
printf("2 GB Discrete Video Card: \t 0.00");
if(addon4 = 1)
printf("4 GB Discrete Video Card: \t 399.00");

printf("================================\n");
}

return 0;
}

最佳答案

您应该使用 addOn 的 bool 数组,而不是声明 3 个不同的变量。并使用函数进行任何修改。

1) 喜欢 buy()
2) 修改()
3)打印()

使用 sum 变量,这将计算总成本。每当要修改账单时,只需将总和作为参数发送到 Modify() 并从总和中添加或减少。

这个方法很简单,试试吧。并确保进行检查,以便客户在不购买商品的情况下无法使用Modify()!

关于c - 如何根据用户的输入计算账单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28447041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com