| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 967 人关注过本帖
标题:说不出的问题!!!
取消只看楼主 加入收藏
小青龙
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-8-2
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:3 
说不出的问题!!!
以下是我自己写的一个简单的小小计算器,只能计算简单加减乘除,我预想中出现的结果应该是:
choose +, -, *, /:+
First number:     6
Second number:    3
Answer:   6 + 3 = 9

choose +, -, *, /:

为什么实际上运行时,出现的结果却是:
choose +, -, *, /:+
First number:     6
Second number:    3
Answer:   6 + 3 = 9

choose +, -, *, /:
Error:Only +, -, *, / are available.Try again!   (注明:为什么就多了这一行呢?这不是我想要的结果啊!原因何在?我总感觉是,当我输入第二个数字3的时候,按下回车键后,回车键的输入值被运用到了  printf("Choose +, -, *, or /:\t");  
                                    scanf("%c", &operator);
                                                                      这两个个语句上,求高人给指点指点!)

以下是我自己写的一个雏形代码,估计有点难看!初学者,还望不要见笑:

#include<stdio.h>

int main ( void )
{
    long a, b;
    char operator;
    long answer;  
   
    while (1)
    {
          printf("Choose +, -, *, or /:\t");
          scanf("%c", &operator);      
         
          switch (operator)
          {              
                       
                 case '+':     
                      {
                          printf("First number:\t\t");
                          scanf("%ld", &a);
                          printf("Second number:\t\t");
                          scanf("%ld", &b);
                          printf("Answer:\t\t%ld %c %ld = %ld\n\n\n", a, operator, b, a+b);
                          break;
                      }  
                 case '-':
                      {
                          printf("First number:\t\t");
                          scanf("%ld", &a);
                          printf("Second number:\t\t");
                          scanf("%ld", &b);
                          printf("Answer:\t%ld %c %ld = %ld\n\n\n", a, operator, b, a-b);
                          break;
                      }
                 case '*':  
                      {
                          printf("First number:\t\t");
                          scanf("%ld", &a);
                          printf("Second number:\t\t");
                          scanf("%ld", &b);
                          printf("Answer:\t%ld %c %ld = %ld\n\n\n", a, operator, b, a*b);
                          break;
                      }
                 case '/':
                      {
                          printf("First number:\t\t");
                          scanf("%ld", &a);
                          printf("Second number:\t\t");
                          scanf("%ld", &b);
                          printf("Answer:\t%ld %c %ld = %ld\n\n\n", a, operator, b, a/b);
                          break;
                      }                                         
                 default:
                         {
                             printf("\nError: Only +, -, *, / are available. Try again!\n\n\n");
                         }
                        
                           
          } /*End of switch */
                     
    }  /* End of while */
}
搜索更多相关主题的帖子: 计算器 number 
2013-08-02 05:35
小青龙
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-8-2
收藏
得分:0 
回复 2楼 wp231957
我目前用的是DEV-C + +,因为之前对c几乎不了解,就随便用了个。
2013-08-02 12:58
小青龙
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-8-2
收藏
得分:0 
回复 5楼 蚕头燕尾
谢谢解答!像我这样的初学者,还是自学者,每走一步,估计都是荆棘满路。
2013-08-02 13:02
小青龙
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-8-2
收藏
得分:0 
回复 2楼 wp231957
另外有一疑问:初学者,用什么编译器好?用高端的好?还是……?
2013-08-02 13:04
快速回复:说不出的问题!!!
数据加载中...
 
   



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

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