#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>//system()函数在此头文件,是调用Windows命令的函数
#include <string.h>
#include <iomanip>
#include <iostream>
struct GOODS {
char num[4];//货物号
char name[21];//货物名
char nameChang[81];//生产厂家
int numtype;//同类产品的数量
float price;//价格
int produceDateyear;//生产日期(年)
int produceDatemonth;//生产日期(月)
int produceDateday;//生产日期(日)
int inyear;//进货日期(年)
int inmonth;//进货日期(年)
int inday;//进货日期(年)
char nameRen[21];//经手人
};
int Input_data(struct GOODS goods[], int nInputtedNum);
int Print_data(struct GOODS goods[], int nInputtedNum);
void Stat_data(struct GOODS goods[], int nInputtedNum);
int main()
{
struct GOODS goods[50] = { 0 };//初始化数组,以方便后续调试
int nInputtedNum = 0;//已入库商品数量
while (1) {
int ch;
system("cls");//"cls"是清空屏幕
printf("欢迎进入仓库管理系统\n\n");
printf("1.清点入库\n\n");
printf("2.查看入库信息\n\n");
printf("3.统计货物总价值\n\n");
printf("0.退出\n\n");
printf("请输入功能序号:\n\n");
ch = _getch();//用于读用户的选项,且此函数不产生回显
if (ch == '0')
break;//退出程序
system("cls");//清屏
switch (ch) {
case '1':
nInputtedNum = Input_data(goods, nInputtedNum);
break;
case '2':
Print_data(goods, nInputtedNum);
break;
case '3':
Stat_data(goods, nInputtedNum);
break;
}
}
return 0;
}
int Input_data(struct GOODS goods[], int i) {
int nInputtedNum;
scanf("%d", &nInputtedNum);
for (i = 0; i <= nInputtedNum; i++)
{
printf("请输入商品号(编号范围为1~9999)\n");
scanf("%s", goods[i].num);
getchar();
printf("请输入商品名称:");
scanf("%s", goods[i].name);
getchar();
printf("请输入生产厂家:");
scanf("%s", goods[i].nameChang);
getchar();
printf("请输入商品数量:");
scanf("%s", &goods[i].numtype);
getchar();
printf("请输入商品单价:");
scanf("%f", &goods[i].price);
getchar();
printf("请输入生产日期:(例如2021 06 01)\n");
scanf("%d%d%d", &goods[i].produceDateyear, &goods[i].produceDatemonth, &goods[i].produceDateday);
getchar();
printf("请输入进货日期:(例如2021 06 01)\n");
scanf("%d%d%d", &goods[i].inyear, &goods[i].inmonth, &goods[i].inday);
getchar();
printf("请输入经手人:\n");
scanf("%s", goods[i].nameRen);
getchar();
//提示语句放到循环内,可能更好一些。
printf("输入END结束入库\n");
//scanf的返回值警告,可自行决定
scanf("%s", goods[nInputtedNum].name);
//如果用户在一行的开始输入了END,则表示用户要结束入库操作
if (!strcmp("END", goods[nInputtedNum].name))
break;
//以下为处理scanf返回值的例子:即未成功输入一个数,则结束输入
if (1 != scanf("%f", &goods[nInputtedNum].price))
break;
}
return nInputtedNum;
}
int Print_data(struct GOODS goods[], int nInputtedNum) {
int i;
char c;
system("cls");
printf("商品号\t商品名称\t生产厂家\t商品数量\t商品单价\t生产日期\t进货日期\t经手人\t");
for (i = 0; i <= nInputtedNum; i++) {
printf("%s\t", goods[i].num);
printf("%s\t\t", goods[i].name);
printf("%s\t\t", goods[i].nameChang);
printf("%d\t\t", goods[i].numtype);
printf("%f\t", goods[i].price);
printf("%04d/%02d/%02d\t", goods[i].produceDateyear, goods[i].produceDatemonth,goods[i].produceDateday);
printf("%04d/%02d/%02d\t", goods[i].inyear, goods[i].inmonth, goods[i].inday);
printf("%s\n", goods[i].nameRen);
}
printf("\n\n");
printf("按任意键返回首页");
_getch(); //应使用此函数
return 0; //要返回一个整数
}
void Stat_data(struct GOODS goods[], int nInputtedNum) {
char c;
system("cls");
int count = 0;
printf("商品总价值为:");
for (int i = 0; i <= nInputtedNum; i++) {
count += (goods[i].numtype * goods[i].price);
}
printf("%d", count);
printf("\n\n");
printf("按任意键返回首页");
c = getchar();
return;
}
这是我之前做的一个仓库管理系统的程序,但是有一些问题没法解决:
最后数据显示存在问题,没有找到能让数据对齐的方法。并且END结束部分也会显示一部分数据。
希望回答的大佬可以把改善上述问题后的代码发出,多谢。
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,已经为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。