根据消费者购买的东西计算电脑商店的账单,我有一个非常令人困惑的问题。可供选择的事项如下:
* 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;
}
答案 0 :(得分:0)
你应该使用addOn的布尔数组,而不是声明3个不同的变量。并进行任何修改使用功能。
1)喜欢买()
2)修改()
3)打印()
使用sum变量,它将计算总成本。每当要修改账单时,只需将sum()作为参数发送到Modify(),然后从总和中添加或减少。
这是一个简单的方法试试吧。并确保检查,以便客户无需购买东西即可使用Modify()!
答案 1 :(得分:0)
首先,使用数组来存储插件。并使用(用户输入 - 1)作为数组索引;
您没有添加价格。在每个检查用户输入的if语句中,也要添加价格。
price = 0
if(addon1 == 1)
{
printf("8 GB Memory: \t 99.00\n");
price += 99.00;
}
else if(addon1 == 2)
{
printf("12 GB Memory: \t 189\n");
price += 189.00
}
.................. 等等。