鱼C论坛

 找回密码
 立即注册
查看: 3772|回复: 2

求高手帮忙,为什么我的程序选择要输入两次!!

[复制链接]
发表于 2013-3-29 09:08:24 | 显示全部楼层 |阅读模式
1鱼币
本帖最后由 Whisper微风 于 2013-4-1 13:35 编辑

#include<stdio.h>
#include<stdlib.h>
struct sales                    //定义销售信息数据结构体
{
char name[8];               //顾客姓名
int sum;                    //销售数量
char time[10];              //销售日期
};
struct product                           //定义商品数据结构
{   
int num;                                 //商品编号   
char productname[20];                    //商品名称   
float price;                             //商品售价   
char place[30];                          //商品产地
int storage;                             //商品库存
};
/********************************函数声明*******************************/
    void Insert();
    void Sales_history();
    void Total_sales();
    void Purchase_history();
    void Customer_information();
/*****************************主菜单****************************/
int select()
{
int i;
printf("\t\t************欢迎使用商品销售管理程序**************\n");
    printf("\n--------------------------------------------------------------------------------\n");  
     printf("                  ************************************\n");
     printf("                  ***                              ***\n");
     printf("                  ***       商品销售管理系统       ***\n");
     printf("                  ***                              ***\n");
     printf("                  ************************************\n");
     printf("                  *            1--插入信息           *\n");
     printf("                  *            2--销售历史           *\n");
     printf("                  *            3--销售总额           *\n");
     printf("                  *            4--购买历史           *\n");
     printf("                  *            5--顾客信息           *\n");
     printf("                  *            0--退出               *\n");
     printf("                  ************************************\n");
printf("\n--------------------------------------------------------------------------------\n");
     printf("                  请输入您的选择(0~5)\n");
printf("你的选择:");
     scanf("%d",&i);                                                                          //接收用户的选择
  return(i);
}
/*******************主函数**********************/
int main()
{
int count=0;   
do
{  
switch(select())
{
case 1:system("cls");Insert(&count);                                                                       //调用插入运算
      break;
case 2:system("cls");Sales_history(count);                                                                 //调用查询销售历史运算
      break;
case 3:system("cls");Total_sales(&count);                                                                  //调用计算销售总额运算
         break;
case 4:system("cls");Purchase_history(count);                                                              //调用查询购买历史运算
      break;
case 5:system("cls");Customer_information(count);                                                          //调用显示运算
      break;
case 0:system("cls");break;
default:{
  system("cls");
  printf("\n\n\n\n\n\n");
     printf("                  *********************************************\n");
  printf("                  ***         错误选择!请重选              ***\n");
     printf("                  ***         请按Enter键返回!!!            ***\n");
  printf("                  *********************************************\n");
  getchar();
  getchar();
  system("cls");  break;
   }
}
}while(select()!=0);
printf("谢谢使用本系统再见!!\n");
return 0;
}
void Insert(int *count)
{
}
void Sales_history(int count)
{
}
void Total_sales(int *count)
{
}
void Purchase_history(int count)
{
}
void Customer_information(int count)
{
}



最佳答案

查看完整内容

首先,在main函数中do...while里面用了一次select(),然后while(select()!=0);用了第二次select(),所以一共用会有两次输入要求。 eg: 在你的代码基础上增加一个变量在do...while前面应该就没问题了。 int a = select(); do { switch(a)...case...select(); }while(a); eg2: int a; while(a = select()) { switch(a)...case...select(); }
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-3-29 09:08:25 | 显示全部楼层
首先,在main函数中do...while里面用了一次select(),然后while(select()!=0);用了第二次select(),所以一共用会有两次输入要求。
eg:
在你的代码基础上增加一个变量在do...while前面应该就没问题了。
int a = select();
do
{
switch(a)...case...select();
}while(a);

eg2:
int a;
while(a = select())
{
switch(a)...case...select();
}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-4-2 16:18:50 | 显示全部楼层
我发现解答问题的鱼友好认真啊!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-4 20:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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