四则运算

#include<stdio.h>

#include <string.h>

float  getNum()
{
float num;
scanf("%f",&num);
return num;
}
char getOpt()
{
return getchar();
}
float caculate(float op1 ,float op2 ,char opt)
{
if(opt=='+')return op1+op2;
if(opt=='-')return op1-op2;
if(opt=='*')return op1*op2;
if(opt=='/')return op1/op2;
return 0;
}
void main()
{
float op1,op2;
char opt;
op1 = getNum();
do
{
opt = getOpt();
if ( opt == '=' ) break;
op2 = getNum();
op1 = caculate(op1,op2,opt);
}while(op1!='');
printf("%f\n",op1);
}

posted @ 2016-03-24 11:38  仙仙仙仙橙  阅读(110)  评论(0)    收藏  举报