| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 440 人关注过本帖
标题:我写的简单计算器代码,请高手看看不好之处!谢谢了!
只看楼主 加入收藏
flysky2011++
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-11-30
收藏
 问题点数:0 回复次数:0 
我写的简单计算器代码,请高手看看不好之处!谢谢了!
void main()
{
    double operand1,operand2,result;
    char ch;
    printf("请输入计算式:\n");
    do
    {
        scanf("%lf%c",&operand1,&ch);
        while(ch!='=')
        {
            scanf("%lf",&operand2);
            switch(ch)
            {
            case '+':
                result=operand1+operand2;
                operand1=result;
                scanf("%c",&ch);
                break;
            case '-':
                result=operand1-operand2;
                operand1=result;
                scanf("%c",&ch);
                break;
            case '*':
                result=operand1*operand2;
                operand1=result;
                scanf("%c",&ch);
                break;
            case '/':
                if(operand2!=0)
                     {
                         result=operand1/operand2;
                           operand1=result;
                        scanf("%c",&ch);
                     }
                    else
                         ch='=';    
                 break;
            case '%':
                if(operand2!=0)
                 {
                         result=(int)operand1%(int)operand2;
                        operand1=result;
                        scanf("%c",&ch);
                 }
                    else
                         ch='=';    
                break;
            default :
                printf("你的运算符错误,请重新编译输入计算式:\n");
                
                break;

            }
        }
        if(operand2!=0)
            printf("%f\n",result);
        else
            printf("运算数为零,请重新编译输入计算式:\n");
    
    }while(operand2!=0);
    
    
}
搜索更多相关主题的帖子: 计算器 代码 
2008-04-16 21:05
快速回复:我写的简单计算器代码,请高手看看不好之处!谢谢了!
数据加载中...
 
   



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

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