vc小程序攻克
/*7.5
编写一个简单的计算器
a op b
*/
#include <stdio.h>
#include <stdlib.h>//引入头文件
int IsOperetor( char ch )//定义函数
{
return (((ch =='+')||(ch=='-')||(ch=='*')||(ch=='/'))?1:0);
}
int main (void)//定义头文件
{
double a,b,res;
char op;
printf("Caculator>");//占用十个空间,一行dos是80个空间,不影响输入算式。
scanf("%lf",&a); //%lf 一次输入避免用户输入习惯造成的困扰。
while( !IsOperetor ( op = getchar()));//不是操作符 一直循环 等待输入
scanf("%lf",&b);
switch( op )//这里面只会是运算符
{
case '+':
res=a + b;
break;//必不可少
case '-':
res=a - b;
break;
case '*':
res=a * b;
break;