鱼C论坛

 找回密码
 立即注册
查看: 3211|回复: 6

printf不输出数据 死循环

[复制链接]
发表于 2022-11-10 21:55:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 爱喝的三明治 于 2022-11-10 23:34 编辑

printf不输出数据
问题出在133和138行之间无线循环
无法输出
在查询这个功能里没办法输出数据
实在是找不到问题在哪里,没有一点头绪

  1. #include <stdio.h>
  2. #include<string.h>
  3. #include <stdlib.h>

  4. struct Goods
  5. {
  6.         int id;//产品编号
  7.         char kudan1;//入库单号
  8.         char kudan2;//出库单号
  9.         char name;//名称
  10.         int num;//数量
  11.         float cost;//成本
  12.         float price;//售价
  13.         float profit;//利润
  14.                
  15. }goods[50],rk[20],ck[20],cx[90];


  16. void input();      
  17. void output();
  18. void search();
  19. void menu();

  20. int main(){

  21.         int command = 0;  //command用于存储管理员命令对应的菜单数字
  22.         int a = 1;      //用于判断是否退出系统
  23.         while(a){       //利用while循环实现对管理系统进行多种操作
  24.             printf("请输入操作对应的数字!如需退出,请输入5!\n\n");
  25.             scanf("%d", &command);
  26.                 switch(command){
  27.                     case(1):        //进库
  28.                             input();
  29.                             break;
  30.                     case(2):        //出库
  31.                             output();
  32.                         break;
  33.                     case(3):        //查询库存
  34.                             search();
  35.                         break;
  36.             
  37.                     default:
  38.                             printf("请输入正确的数字!\n\n");   //提示管理员重新输入正确的菜单数字
  39.                              break;
  40.             }
  41.         }
  42.         printf("  从");   //提示管理员成功退出系统
  43.         return 0;
  44. }


  45. int S=0;//产品种类
  46. void input()//入库
  47. {
  48.         int a,i=0,j=0;
  49.         printf("请输入入库产品种类:\n");
  50.         scanf("%d",&a);
  51.         for(j=0;j<a;j++)
  52.         {        printf("请输入第%d个产品信息\n",(j+1));
  53.             printf("产品名称:");
  54.         scanf("%s",&goods[i].name);               
  55.             printf("产品编号:");
  56.             scanf("%d",&goods[i].id);
  57.             printf("例:2022年1月填为202201\n");
  58.                 printf("入库单号:\n");
  59.                 scanf("%s",&goods[i].kudan1);
  60.                 printf("数量:");
  61.                 scanf("%d",&goods[i].num);
  62.                 printf("请再输入一次\n");
  63.                 scanf("%d",&rk[i].num);

  64.                 int flag = 0;  
  65.         for(i = 0; i <S; i++)
  66.                 {  
  67.                 if(rk[i].id==goods[i].id)
  68.                         {flag = 1;
  69.                         goods[i].num =rk[i].num+goods[i].num;
  70.                         break;
  71.                     }
  72.                 }
  73.                     if (flag == 0)
  74.                         {
  75.                 S++;
  76.                 }
  77.         }               
  78. }

  79. void output()//出库
  80. {
  81. }

  82. void search()
  83. {
  84.         int i,s,flag;
  85.         printf("1.查询入库单\n");
  86.         printf("2.查询出库单\n");
  87.         printf("3.退出菜单\n");
  88.         while(1){
  89.         printf("请选择编号:");
  90.     scanf("%d",&s);
  91.     flag=0;
  92.     switch(s){
  93.         case 1:
  94.         printf("请输入要查询入库单号:\n");
  95.     scanf("%d",&cx[i].kudan1);
  96.     for(i=0;i<S;i++)
  97.         if(goods[i].kudan1==cx[i].kudan1) {
  98.         flag=1;
  99.         printf("入库单号  编号  名称  数量  成本\n");
  100.         printf("%d%d%s%d%f\n",goods[1].kudan1,goods[i].id ,goods[i].name ,goods[i].num ,goods[i].cost);}
  101.     if(flag=0)
  102.         printf("该单号不存在!\n");
  103.     break;
  104.         case 2:
  105.         printf("请输入要查询出库单号:\n");
  106.     scanf("%d",&cx[i].kudan2);
  107.     for(i=0;i<S;i++)
  108.         if(goods[i].kudan2==cx[i].kudan2){
  109.         flag=1;
  110.         printf("出库单号  编号  名称  数量  利润\n");
  111.         goods[i].profit=goods[i].price-goods[i].cost;
  112.         printf("%d%d%s%d%f\n",goods[1].kudan2,goods[i].id ,goods[i].name ,goods[i].num ,goods[i].profit);}
  113.     if(flag=0)
  114.         printf("该单号不存在!\n");
  115.     break;
  116.     case 3:
  117.     return;
  118.         default:
  119.                 printf("ddd");
  120.                 break;
  121.         }
  122.   }
  123. }
  124.   




复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-11-10 22:12:03 | 显示全部楼层
本帖最后由 jackz007 于 2022-11-10 22:22 编辑

        39 行有错误,必须修改
  1. void search()
  2. {
  3. . . . . . .
  4.         switch(s) {
  5.                 case 1:
  6. . . . . . .
  7.                 if(flag == 0)       // 【错误】:39 行
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-11-10 22:22:37 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-10 22:24:21 | 显示全部楼层
本帖最后由 jackz007 于 2022-11-10 22:27 编辑


         你代码的 39 行看不出问题?
         提醒一下,判断相等要用 == ,不可以用 =,你最先贴出的代码在 case 2 的语句块内也存在完全一样的问题,还是 if (flag = 0)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-11-10 22:32:37 | 显示全部楼层
jackz007 发表于 2022-11-10 22:24
你代码的 39 行看不出问题?
         提醒一下,判断相等要用 == ,不可以用 =,你最先贴出 ...

已改,但是还有问题啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-11-10 22:42:07 | 显示全部楼层
爱喝的三明治 发表于 2022-11-10 22:32
已改,但是还有问题啊

          要想解决问题,那就把代码贴全,代码必须要处于可编译、可运行状态。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-11-10 22:43:06 | 显示全部楼层
jackz007 发表于 2022-11-10 22:42
要想解决问题,那就把代码贴全,代码必须要处于可编译、可运行状态。

收到,立马贴
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-13 00:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表