#include <stdio.h>
#include <stdlib.h> typedef enum
{
FALSE = ,
TRUE
}BOOL; void calculator(void); int main(void)
{
char y = ' ';
y = 'y';
while('y' == y)
{
printf("start calculator:\n");
calculator();
printf("restart?,printf 'y' to continue\n");
scanf(" %c",&y);
printf("%c\n",y);
}
return ;
} void calculator(void)
{
char c;
char ucOperator = ' ';
int k = ;
int value = ;
int lastValue = ;
int result = ;
int lastk; printf("start calculator input:\n");
/* while((c = getchar()) == '\n'||c == ' ')
{
;
}
//this does work,the below way is more simple
*/
scanf(" %c",&c); //filter space and return
do{
if(c >= '' && c <= '')
{
if(!value)
{
value = c - '';
}
else
{
value = value* + c- '';
}
continue;
} if('+' == c)
{
lastk = k;
k = ;
}
else
{
if('-' == c)
{
lastk = k;
k = -;
c = '+';
}
} switch(c)
{
case '+':
switch(ucOperator)
{
case '*':
result += lastValue * value * lastk;
break;
case '/':
result += lastValue / value * lastk;
break;
case '+':
result += value * lastk;
break;
case ' ':
result += value;
break;
default:
break;
}
ucOperator = '+';
break; case '*':
lastValue = value; ucOperator = '*';
break;
case '/':
lastValue = value; ucOperator = '/';
break;
case '=':
if('+' == ucOperator)
{
result += value * k;
}
if('*' == ucOperator)
{
result += value * lastValue * k;
}
if('/' == ucOperator)
{
result += lastValue / value * k;
}
printf("%d\n",result);
result = ;
ucOperator = ' ';
break;
default:
break;
}
value = ;
}while((c = getchar()) != '\n');
}

calculator的更多相关文章

  1. [LeetCode] Basic Calculator II 基本计算器之二

    Implement a basic calculator to evaluate a simple expression string. The expression string contains ...

  2. [LeetCode] Basic Calculator 基本计算器

    Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...

  3. Basic Calculator II

    Implement a basic calculator to evaluate a simple expression string. The expression string contains ...

  4. Windows Universal 应用 – Tip Calculator

    声明 以下内容取材于 Bob Tabor 的课程<Windows Phone 8.1 Development for Absolute Beginners>,链接地址为:http://ww ...

  5. Calculator(1.5)

    Calculator(1.5) Github链接 ps.负数的处理未完成 解题过程中遇到的困难和解决 <stack>的使用: 认真研究了栈,基本上掌握了用法,与<queue>的 ...

  6. Calculator(1.0)

    Calculator(1.0) Github链接 解题过程中遇到的困难 对于c++中类和对象的使用不够明确,看了c++的视频教程学会了用类和对象来写程序. 不会使用<queue>,在网上查 ...

  7. 数据结构与算法(1)支线任务2——Basic Calculator

    题目:https://leetcode.com/problems/basic-calculator/ Implement a basic calculator to evaluate a simple ...

  8. Basic Calculator

    本博客介绍leetcode上的一道不难,但是比较经典的算法题. 题目如下: Implement a basic calculator to evaluate a simple expression s ...

  9. Matrix Calculator

    表达式分析+矩阵+计算器+寄存器=矩阵计算器 怎么想起来搞这个呢.. //刚看龙书兴致勃勃要搞表达式分析 这个寄存器比较简陋,26字母+4缓存,//字母不分大小写 当然,不只能算矩阵,还能算数= = ...

随机推荐

  1. 影响性能的关键部分-ceph的osd journal写

    在前面一篇文章中,我们看到,当使用filestore时,osd会把磁盘分成data和journal两部分.这主要是为了支持object的transaction操作.我的想法是,ceph需要具有数据保护 ...

  2. 优化定时器NSTimer-runloop使用

    参考文档:http://www.cnblogs.com/junhuawang/p/4647559.html   - (void)viewDidLoad { [super viewDidLoad];   ...

  3. 汇编语言学习与Makefile入门

    继续开发 ; hello-os ; TAB= ORG 0x7c00 ; 指明程序的装载地址 ; 以下的记述用于标准FAT12格式的软盘 JMP entry DB 0x90 DB "HELLO ...

  4. webUploader react 接口设计

    import React, {PropTypes} from 'react'; export default class Test extends React.Component { construc ...

  5. 树莓派3B 安装微雪LCD5inch显示器(包含软键盘)

    树莓派单独使用时,往往需要触摸屏和软键盘用以方便操作,微雪LCD显示器就能较好的实现这个功能, 正好实验室又买入了一个3B的板子和一个5inch的显示器,便对着官方的安装手册,亲自安装了一次. 一:材 ...

  6. things to analysis

    Started by timer [EnvInject] - Loading node environment variables. Building remotely on RE_DEV_BUILD ...

  7. 最小安装模式下Centos7.*网卡启动配置

    最小安装模式下的Centos7.*系统默认情况下,网卡是不启动的.为了解决联网问题,自己搜集了点资料,成功连接了网络.并梳理了下处理过程. 1.首先运行ip addr命令,查看配置文件的名称.有的文章 ...

  8. android sdk manager 代理设置(送给牛逼的)

    解决android sdk更新慢的问题(公司竟然把sdk更新给墙了). 第一步:如下图 第二部:进入代理设置页面,进行设置.如下图  

  9. PHP语法基础

    1.PHP语法基础 PHP标记符 <?php ?> 常亮与变量 $a = 10; 变量 可以在运行过程中修改 $a = 10; $a = 20; $b = 5; echo $a+$b; c ...

  10. iOS 为iPhone和iPad创建不同的storyboard

    复制Main.storyboard,重命名为Main_iPad.storyboard 在info.plist文件中添加 Main storyboard file base name (iPad) -- ...