| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 796 人关注过本帖
标题:简单到令人发指的 小程序--计算器
取消只看楼主 加入收藏
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
结帖率:100%
收藏
 问题点数:0 回复次数:0 
简单到令人发指的 小程序--计算器
不多说了,各位看代码吧。
程序代码:
// 简单计算器.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
#include<math.h>
using namespace std;
double firstnum,secondnum,thirdnum,resultnum;
char sign1,sign2;
void input()
{
    cin>>firstnum>>sign1>>secondnum>>sign2>>thirdnum;
}
void output()
{
    cout<<"="<<resultnum<<'\n';
}
double yunsuan()
{
    if(sign1=='+'&&sign2=='+')
    {
      resultnum=firstnum+secondnum+thirdnum;
    }
    if(sign1=='+'&&sign2=='-')
    {
      resultnum=firstnum+secondnum-thirdnum;
    }
    if(sign1=='+'&&sign2=='*')
    {
      resultnum=firstnum+secondnum*thirdnum;
    }
    if(sign1=='+'&&sign2=='/')
    {
      resultnum=firstnum+secondnum/thirdnum;
    }
    if(sign1=='+'&&sign2=='^')//~~~~~~~~~~第一运算符为加法~~~~~~~~~~~~~~~~~~~~
    {
            resultnum=firstnum+pow(secondnum,thirdnum);
    

    }
    if(sign1=='-'&&sign2=='+')
    {
      resultnum=firstnum-secondnum+thirdnum;
    }
    if(sign1=='-'&&sign2=='-')
    {
      resultnum=firstnum-secondnum-thirdnum;
    }
    if(sign1=='-'&&sign2=='*')
    {
      resultnum=firstnum-secondnum*thirdnum;
    }
    if(sign1=='-'&&sign2=='/')
    {
      resultnum=firstnum-secondnum/thirdnum;
    }
    if(sign1=='-'&&sign2=='^')//~~~~~~~~~~第一运算符为减~~~~~~~~~~~~~~~~~~~~
    {
            resultnum=firstnum-pow(secondnum,thirdnum);
    

    }
    if(sign1=='*'&&sign2=='+')
    {
      resultnum=firstnum*secondnum+thirdnum;
    }
    if(sign1=='*'&&sign2=='-')
    {
      resultnum=firstnum*secondnum-thirdnum;
    }
    if(sign1=='*'&&sign2=='*')
    {
      resultnum=firstnum*secondnum*thirdnum;
    }
    if(sign1=='*'&&sign2=='/')
    {
      resultnum=firstnum*secondnum/thirdnum;
    }
    if(sign1=='*'&&sign2=='^')//~~~~~~~~~~~第一运算符为乘~~~~~~~~~~~~~~~~~~~
    {
            resultnum=firstnum*pow(secondnum,thirdnum);
    

    }
    if(sign1=='/'&&sign2=='+')
    {
      resultnum=firstnum/secondnum+thirdnum;
    }
    if(sign1=='/'&&sign2=='-')
    {
      resultnum=firstnum/secondnum-thirdnum;
    }
    if(sign1=='/'&&sign2=='*')
    {
      resultnum=firstnum/secondnum*thirdnum;
    }
    if(sign1=='/'&&sign2=='/')
    {
      resultnum=firstnum/secondnum/thirdnum;
    }
    if(sign1=='/'&&sign2=='^')//~~~~~~~~~~~第一运算符为除~~~~~~~~~~~~~~~~~~~
    {
            resultnum=firstnum/pow(secondnum,thirdnum);
    

    }
    if(sign1=='^'&&sign2=='+')
    {
      resultnum=pow(firstnum,secondnum)+thirdnum;
    }
    if(sign1=='^'&&sign2=='-')
    {
      resultnum=pow(firstnum,secondnum)-thirdnum;
    }
    if(sign1=='^'&&sign2=='*')
    {
      resultnum=pow(firstnum,secondnum)*thirdnum;
    }
    if(sign1=='^'&&sign2=='/')
    {
      resultnum=pow(firstnum,secondnum)/thirdnum;
    }
    if(sign1=='^'&&sign2=='^')//~~~~~~~~~~第一运算符为幂运算~~~~~~~~~~~~~~~~~~~~
    {
            resultnum=pow(firstnum,secondnum);
            resultnum=pow(resultnum,thirdnum);
    

    }
    return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
    for(;;)
    {
    cout<<"现在开始运算:"<<'\n';
    input();
    yunsuan();
    output();
    }
    return 0;
}
搜索更多相关主题的帖子: 计算器 应用程序 控制台 
2011-04-29 18:47
快速回复:简单到令人发指的 小程序--计算器
数据加载中...
 
   



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

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