| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 912 人关注过本帖
标题:c语言做的简单计算器有问题;
取消只看楼主 加入收藏
fhyega
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-8-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
c语言做的简单计算器有问题;
现在只是测试阶段
我想问问这段代码有什么问题:(为什么一运行输入后就无响应)
各位看看哪里可以改一下
#include <stdio.h>

int main()
{
        char ch[20];
        int j,i,a[40],num[21];
        
        for(i=1;i<10;++i)
        {
                scanf("%d",&num[i]);
                if(getchar()=='.')
                {
                        a[i*2-1] = '.';
                        break;
                }
                else
                scanf("%c",&a[i*2-1]);
                scanf("%c",&ch[i]);
                scanf("%c",&a[i*2]);
               
        }
        
        for(i=1;;i++)
        {
                if(a[i*2] == '(')
                {
                        switch(ch[i+1])
                        {
                        case '+':
                                {
                                        num[i+1] += num[i+2];
                                        ch[i+1] = '+';
                                        num[i+2] = 0;
                                }
                        case '-':
                                {
                                        num[i+1] -= num[i+2];
                                        ch[i+1] = '+';
                                        num[i+2] = 0;
                                }
                        }
                }
                if(a[i*2-1] == '.')
                        break;
        }
        
        for(j=0;j<20;j++)
        {
                for(i=1;;i++)
                {
                        if(a[i*2-1] == '.')
                                break;
                        switch(ch[i])
                        {
                        case '+':
                                {
                                        num[i] += num[i+1];
                                        ch[i+1] = '+';
                                        num[i+1] = 0;
                                }
                        case '-':
                                {
                                        num[i] -= num[i+1];
                                        ch[i+1] = '+';
                                        num[i+1] = 0;
                                }
                        }
                }
        }
        
        printf("%d",num[1]);
        
        return 0;
}
搜索更多相关主题的帖子: 计算器 include c语言 
2016-08-02 23:09
fhyega
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-8-2
收藏
得分:0 
回复 2楼 书生牛犊
不是呀,我是按“数字(空格或括号)运算符号(空格或括号)数字”输入的,然后多个式子后以结束符结尾的,例如"1 + "就是一次循环
2016-08-03 21:32
fhyega
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-8-2
收藏
得分:0 
回复 2楼 书生牛犊
哦,先改一改
2016-08-03 21:33
快速回复:c语言做的简单计算器有问题;
数据加载中...
 
   



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

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