C语言实现超市计价收款系统

作者:不吃肉的胖子 时间:2021-08-21 17:56:47 

本文实例为大家分享了C语言实现超市计价收款系统的具体代码,供大家参考,具体内容如下

学习一个月的C语言,写了一个简易的超市计价收款系统

C语言实现超市计价收款系统

源码如下

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 10
typedef struct ? ?//定义商品的结构体?
{ ??
? ? ?
?? ?char name[10];
?? ?int num;
?? ?float ?price;?
?? ?int ID;?
}Store;
Store store[M];

void shuru( ) ? //定义输入商品的函数?
{
?? ?int i;
?? ?int isgo;
?? ?int n;
?? ?for(i=0;i<M;i++)
?? ?{
?? ??? ?store[i].ID=i+1;//自定义商品的ID?
?? ??? ?printf("输入商品的名字\n");
?? ??? ?scanf("%s",&store[i].name);?
?? ??? ?printf("输入商品的价格\n");
?? ??? ?scanf("%f",&store[i].price);?
?? ??? ?printf("还需要输入商品吗?\n");
?? ??? ?printf("1.YES,2.NO\n");
?? ??? ?scanf("%d",&isgo);
?? ??? ?if(isgo!=2)//判断是否继续输入商品?
?? ??? ?{
?? ??? ??? ?
?? ??? ?}else//不输入商品直接跳出,展示所有商品的信息?
?? ??? ?{
?? ??? ??? ?for(n=0;n<=i;n++)
?? ??? ? ? ?{
?? ??? ? ? ? ? ?printf("商品ID\t商品名字\t商品价格\n");
?? ??? ? ? ? ? ?printf("%d\t,%s\t,%f\n",store[n].ID,store[n].name,store[n].price);
?? ??? ? ? ?}
?? ??? ? ? ?i=10;
?? ??? ?}
?? ??? ?
?? ?}
}

void shopp() ?//购物函数?
{
?? ?int isgo=1;
?? ?int i;
?? ?int n;
?? ?int number;
?? ?int shoppid;?
?? ?float pricenum;
?? ?float pricesum=0.0;
?? ?float priceguke;
?? ??
?? ?
?? ?printf("库存的商品如下\n");
?? ?for(n=0;n<M;n++)
? ? {
? ??? ? ? printf("商品ID\t商品名字\t商品价格\n");
?? ? ? printf("%d\t,%s\t,%f\n",store[n].ID,store[n].name,store[n].price);
?? ? ? if(store[n].price==0)//这里是为了不把没定义的商品不显示出来?
?? ? ? {
? ??? ??? ?n=M;
? ??? ? ? }
?? ?
?? ? ??
? ? }
?? ?while(isgo)//购物?
?? ?{
?? ??? ?printf("按下你需要的商品ID和数量\n");
?? ??? ?scanf("%d,%d",&shoppid,&number);
?? ??? ?pricenum=(store[shoppid-1].price)*number;
?? ??? ?pricesum=pricesum+pricenum;
?? ??? ?printf("你购买的商品%s是%d个,价格是%f,总金额是%f\n",store[shoppid-1].name,number,pricenum,pricesum);
?? ??? ?printf("是否继续购物\n");
?? ??? ?printf("0.退出,1.继续\n");
?? ??? ?scanf("%d",&isgo);?
?? ?}
?? ?printf("输入顾客支付的金钱\n");//结算?
?? ?scanf("%f",&priceguke);
?? ?if(priceguke>=pricesum)
?? ?{
?? ??? ?printf("收到顾客%f元,找回顾客%f元\n",priceguke,priceguke-pricesum);
?? ?}else
?? ??? ?{
?? ??? ?printf("收到的钱小于总金额\n");
?? ?}
?? ?printf("谢谢光临\n");
?? ??? ?
}

main()
{
?? ?int xitong=1;
?? ?

?? ?while(xitong!=3)
?? ?{
?? ??? ?printf("-------------------欢迎登录好浪费超市系统-----------------------\n");
? ??? ? ? ?printf("1.输入商品信息\n");
?? ? ? ?printf("2.购买商品\n");
? ? ? ? printf("3.退出系购买商品统\n");
?? ? ? ?scanf("%d",&xitong);
?? ? ? ?switch(xitong)
?? ? ? ?{
? ? ?? ??? ?case 1:shuru();
? ? ?? ??? ?break;
? ? ?? ??? ?case 2:shopp();
? ? ?? ??? ?break;
? ? ?? ??? ?case 3:printf("欢迎再次使用好浪费超市系统\n");?
? ? ?? ?}
?? ??? ??? ??? ?
?? ?}
}

来源:https://blog.csdn.net/qq_43547520/article/details/118652441

标签:C语言,收款系统
0
投稿

猜你喜欢

  • 学生信息管理系统java版

    2023-06-16 15:48:10
  • Unity使用ScrollRect制作翻页

    2023-05-22 09:10:44
  • SpringMVC中重定向model值的获取方式

    2022-08-25 11:22:09
  • android TextView中识别多个url并分别点击跳转方法详解

    2023-06-21 04:42:32
  • Springcloud Eureka配置及集群代码实例

    2021-09-19 05:54:52
  • 基于CXF搭建webService的实例讲解

    2023-07-02 10:41:34
  • MyBatis执行Sql的流程实例解析

    2022-06-12 19:43:42
  • vs 中C#项目读取JSON配置文件的方法

    2022-09-22 15:04:05
  • Java线程之守护线程(Daemon)用法实例

    2023-11-29 09:15:13
  • 移动端WebApp隐藏地址栏的方法

    2022-09-26 20:26:29
  • C++ 继承,虚继承(内存结构)详解

    2023-09-05 21:28:01
  • 解决idea中yml文件图标问题及自动提示失效的情况

    2021-06-08 14:59:42
  • 简单实现C#异步操作

    2022-09-05 06:03:00
  • java常用工具类之DES和Base64加密解密类

    2023-12-20 17:48:31
  • 详解Spring boot/Spring 统一错误处理方案的使用

    2023-11-24 12:56:07
  • Android中ViewPager组件的基本用法及实现图片切换的示例

    2021-09-28 17:49:42
  • C#实现的Win32控制台线程计时器功能示例

    2022-12-19 20:29:20
  • Java实现企业发放的奖金根据利润提成问题

    2023-02-11 06:52:33
  • C#验证给定字符串是否为数字的方法

    2021-08-24 10:22:21
  • SpringBoot手动使用EhCache的方法示例

    2023-04-24 03:50:30
  • asp之家 软件编程 m.aspxhome.com