getch()写入和scanf问题

 

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

void main()
{
 int button,password,password1,i,Cmoney,a,b;
 a=0;
 button=0;
 password=123456;
 password1=123456;
 i=1;

 do
 {
  system("cls");
  printf("***************************\n");
  printf("*   please select key:    *\n");
  printf("*   1.password            *\n");
  printf("*   2.get money           *\n");
  printf("*   3.Return              *\n");
  printf("***************************\n");
  printf("   press 1-3 to select:\n");
  scanf("%d",&button);
 }
 while(button!=1 && button!=2 && button!=3);

 switch(button)
 {
  case 1:
   printf("please input password:\n");
   scanf("%d",password);
   if(password1!=password)
   {
    if(i>3)
    {
     printf("input error,please press any key to exit!\n");
     getch();
     exit(0);
    }
    else
    {
     printf("input error,please input again!\n");
    }
   }

   else
   {
    printf("input right!,continue do!");
   }
  case 2:
   do
   {
    system("cls");
    if(password1!=password)
    {
     printf("please press any key to continue!\n");
     getch();
     break;
    }
    else
    {
     printf("******************************\n");
     printf("*      please select         *\n");
     printf("*      1.$ 100               *\n");
     printf("*      2.$ 200               *\n");
     printf("*      3.$ 300               *\n");
     printf("*      4.input other number which you want\n");
     printf("*      5.Return              *\n");
     Cmoney=getch();
    }
   }
   while (Cmoney!=1 && Cmoney!=2 && Cmoney!=3  && Cmoney!=4 && Cmoney!=5);

   switch(Cmoney)
   {
   case 1:
    system("cls");
    a=a-100;
    printf("*****************************************\n");
    printf("* Your Credit money is $ 100,Thank You! *\n");
    printf("*         The balance is %d.            *\n",a);
    printf("*         Press any key to return       *\n");
    printf("*****************************************\n");
    getch();
    break;
   case 2:
    system("cls");
    a=a-200;
    printf("*****************************************\n");
    printf("* Your Credit money is $ 200,Thank You! *\n");
    printf("*         The balance is %d.            *\n",a);
    printf("*         Press any key to return       *\n");
    printf("*****************************************\n");
    getch();
    break;
   case 3:
    system("cls");
    a=a-300;
    printf("*****************************************\n");
    printf("* Your Credit money is $ 300,Thank You! *\n");
    printf("*         The balance is %d.            *\n",a);
    printf("*         Press any key to return       *\n");
    printf("*****************************************\n");
    getch();
    break;
   case 4:
    system("cls");
    printf("please input the money which you want to take.\n");
    scanf("%d",&b);
    a=a-b;
    printf("*****************************************\n");
    printf("* Your Credit money is $ b,Thank You! *\n");
    printf("*         The balance is %d.            *\n",a);
    printf("*         Press any key to return       *\n");
    printf("*****************************************\n");
    getch();
    break;
   case 5:
    break;
   }
  case 3:
   printf("****************************************\n");
   printf("*     Thank you for your using!        *\n");
   printf("*            GOODBYE!                  *\n");
   printf("****************************************\n");
   getch();
   break;
 }
}

每次进入一个页面输入按键指令时,这里的getch不能成功输入。但是我改成scanf可以合法输入并进入下一步菜单。如果我只用getch输入,应该如何修改。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值