#include "stdio.h"
void main(void){
//手机购物程序设计
float V8Price=2288;//手机V8的价格
float MATE7Price=2588;//手机MATE7的价格
float phoneShellPrice=20;//手机壳的价格
float TotalPrice=0;//购物的这个花费
int V8Amount=0;//购买手机V8的数量
int MATE7Amount=0;//购买手机MATE7 的数量
int phoneShellAmount=0;//购买手机壳的数量
int TotalAmount=0;//购买商品的数量
int isContinue=1;//是否继续购物
int goodsType=1;//选择的购物商品的种类
int goodsNum=0;//选择购物商品的数量
float goodsPrice=0;//单次商品的单价金额
printf("\t\t\t欢迎来到淘宝百货商城\t\t\t\n");
while(isContinue){
printf("请选择你需要的商品:\n");
printf("编号 手机种类 手机价格\n");
printf(" 1 V8 2288 \n");
printf(" 2 MATE7 2588 \n");
printf(" 3 phoneShell 20 \n");
printf("\n\n");
printf("请选择你需要的商品编号:");
scanf("%d",&goodsType);
printf(" 请输入你需要的数量:");
scanf("%d",&goodsNum);
TotalAmount+=goodsNum;
if(goodsType==1){
goodsPrice=V8Price;
V8Amount+=goodsNum;
}else if(goodsType==2){
goodsPrice=MATE7Price;
MATE7Amount+=goodsNum;
}else if(goodsType==3){
goodsPrice=phoneShellPrice;
phoneShellAmount+=goodsNum;
}else{
printf("\n\n 你选择的商品类别有误!\n\n");
TotalAmount-=goodsNum;
}
TotalPrice+=goodsPrice*goodsNum;
printf("\n");
printf("本次购物单:\n");
printf("商品名称 商品数量 商品金额\n");
//显示购买的商品名称和数量
if(goodsType==1){
printf(" v8 %d %f\n",V8Amount,V8Amount*V8Price);
}
if(goodsType==2){
printf(" MATE7 %d %f\n",MATE7Amount,MATE7Amount*MATE7Price);
}
if(goodsType==3){
printf("phoneShell %d %f\n",phoneShellAmount,phoneShellAmount*phoneShellPrice);
}
if(V8Amount==0&&MATE7Amount==0&&phoneShellAmount==0){
printf("\n\t您还没有购物!\n");
}
printf("\n");
printf(" 购买的商品数量为:%d\n",goodsNum);
printf(" 商品总额为:%f\n\n",goodsPrice*goodsNum);
printf("是否继续购物:继续:1 退出:0\n");
scanf("%d",&isContinue);
printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
printf("\n\n");
}
printf("\n");
printf("你的购物单:\n");
printf("商品名称 商品数量 商品金额\n");
//显示购买的商品名称和数量
if(V8Amount!=0){
printf(" v8 %d %f\n",V8Amount,V8Amount*V8Price);
}
if(MATE7Amount!=0){
printf(" MATE7 %d %f\n",MATE7Amount,MATE7Amount*MATE7Price);
}
if(phoneShellAmount!=0){
printf("phoneShell %d %f\n",phoneShellAmount,phoneShellAmount*phoneShellPrice);
}
if(V8Amount==0&&MATE7Amount==0&&phoneShellAmount==0){
printf("\n\t您还没有购物!\n");
}
printf("\n");
printf(" 您购买的商品数量为:%d\n",TotalAmount);
printf(" 商品总额为:%f\n\n",TotalPrice);
printf("欢迎再次光临!\n");
}