| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 429 人关注过本帖
标题:求助:关于这个程序的循环问题..
取消只看楼主 加入收藏
z562586756
Rank: 1
等 级:新手上路
帖 子:18
专家分:1
注 册:2011-4-30
结帖率:16.67%
收藏
 问题点数:0 回复次数:1 
求助:关于这个程序的循环问题..
#include<stdio.h>
#include<stdlib.h>
int get_num (void);
char get_first (void);
char get_choice (void);
int add (void);
int sub (void);
int mul (void);
int div (void);
int main (void)
{
    int choice;
    printf("HELLO!!!\n");
    while ((choice=get_choice())!='q')
    {
          switch (choice)
          {
          case 'a':add();
          break;
          case 's':sub();
          break;
          case 'm':mul();
          break;
          case 'd':div();
          break;
          default:printf("input error");
          }
          }
          printf("bye");
          system("pause");
          }
          char get_choice ()
          {
                     char ch;
                     printf("Enter the operation of your chice\n");
                     printf("a.add            s.subtrct\n");
                     printf("m.multiply       d.divide\n");
                     printf("q.quit\n");
                     ch=get_first();
                     while (ch!='a'&&ch!='s'&&ch!='m'&&ch!='d'&&ch!='q')
                     {
                           printf("please input a,s,m,d or q\n");
                           ch=get_first();
                           }
                           return ch;
                           }
          char get_first ()
          {
               char ch;
               ch=getchar();
               while(getchar()!='\n')
               continue;
               return ch;
               }
               int add ()
               {
                   int num_1,num_2;
                   printf("Enter the first number:\n");
                   num_1=get_num();
                   printf("Enter the second number\n");
                   num_2=get_num();
                   printf("%d+%d=%d",num_1,num_2,num_1+num_2);
                   }
                   int sub ()
                   {
                   int num_1,num_2;
                   printf("Enter the first number:\n");
                   num_1=get_num();
                   printf("Enter the second number\n");
                   num_2=get_num();
                   printf("%dX%d=%d",num_1,num_2,num_1*num_2);
                   }
                   int mul ()
                   {
                   int num_1,num_2;
                   printf("Enter the first number:\n");
                   num_1=get_num();
                   printf("Enter the second number\n");
                   num_2=get_num();
                   printf("%d-%d=%d",num_1,num_2,num_1-num_2);
                   }
                   int div ()
                   {
                   int num_1,num_2;
                   printf("Enter the first number:\n");
                   num_1=get_num();
                   printf("Enter the second number\n");
                   num_2=get_num();
                   printf("%d/%d=%d",num_1,num_2,num_1/num_2);
                   }
                   int get_num()
                   {
                       int num;
                       char ch;
                       while (scanf("%d",&num)!=1)
                       {
                             while ((ch=getchar())!='\n')
                             putchar(ch);
                             printf("is not a integer,please input such as 1, 85,65");
                             }
                             return num;
                             }

运行后正常,但进入第一次循环,不管输入什么都显示please input a,s,m,d or q,是哪里弄错了啊,虚心求教。。。
                       
                       
                  
                  
               
         
                     
         

   
搜索更多相关主题的帖子: default 
2011-07-29 10:26
z562586756
Rank: 1
等 级:新手上路
帖 子:18
专家分:1
注 册:2011-4-30
收藏
得分:0 
回复 3楼 吴辉
这样子好像还是不可以的啊。。
2011-07-29 12:09
快速回复:求助:关于这个程序的循环问题..
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016788 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved