| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:我写的简单计算器代码?请高手指点一下,不胜感谢!
取消只看楼主 加入收藏
flysky2011++
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-11-30
收藏
 问题点数:0 回复次数:0 
我写的简单计算器代码?请高手指点一下,不胜感谢!
#include<stdio.h>
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);
    
    
}
搜索更多相关主题的帖子: 计算器 result scanf 
2008-04-16 21:09
快速回复:我写的简单计算器代码?请高手指点一下,不胜感谢!
数据加载中...
 
   



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

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