当前位置:首页 » 编程语言 » c语言买冰球
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言买冰球

发布时间: 2023-06-10 09:43:41

A. 请问c语言如何实现输入一个商品的名字和购买数量,自动计算出总价,商品有苹果和梨子,单价分别是10和

#define_CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
structgoods
{
chargoodsName[20];
intgoodNum;
};
intpriceCount(structgoodsinputGoods)
{
if(!strcmp(inputGoods.goodsName,"苹果"))
returninputGoods.goodNum*10;
if(!strcmp(inputGoods.goodsName,"梨子"))
returninputGoods.goodNum*11;
else
return-1;
}

intmain()
{
structgoodsinputGoods={};
while(1)
{
printf("请输入商品名字和购买数量 ");
scanf("%s%d",inputGoods.goodsName,&inputGoods.goodNum);
if(priceCount(inputGoods)!=-1)
printf("购买%s的总价是:%d ",inputGoods.goodsName,priceCount(inputGoods));
else
//printf("我头像,惊喜")
printf("商品名字输入有问题 ");
}
system("pause");
return0;
}

运行结果:

B. C语言程序

#include<stdio.h>
intmain()
{
floatval=0.0;
printf("输入火腿肠数量:");
scanf("%f",&val);
floatnum=val*10.5;
printf("
输入方便面数量:");
scanf("%f",&val);
num+=val*12.5;
printf("
输入牛奶数量:");
scanf("%f",&val);
num+=val*55.9;
printf(" 应付金额%f¥输入支付金额:",num);
scanf("%f",&val);
printf(" 应找顾客金额:%f",val-num);
scanf("%f",&val);
return0;
}