问题及代码:
/*
*Copyright (c)2014,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:calculate.cpp
*作 者:单昕昕
*完成日期:2014年10月30日
*版 本 号:v1.0
*
*问题描述:输入想要计算的式子及四则运算符。本程序设定计算十个式子。
*程序输出:运算结果。
*/
#include <iostream>
using namespace std;
int main()
{
int a = 100;
int b = 20;
int c,m=1;
char oper;
while(m<=10)// 限定计算十个式子。
{
cin>>a>>oper>>b;
switch(oper) //oper即operation,这里表示四则运算符。
{
case '+':
c = a + b;
++m;
cout<<"c="<<c<<endl;
continue;
case '-':
c = a - b;
++m;
cout<<"c="<<c<<endl;
continue;
case '*':
c = a * b;
++m;
cout<<"c="<<c<<endl;
continue;
default :
if( b==0)
{
c = a;
++m;
cout<<"c="<<c<<endl;
}
else
c = a / b;
++m;
cout<<"c="<<c<<endl;
continue;
}
}
return 0;
}
运行结果:
知识点总结:
利用continue和while循环语句实现多次计算并输出结果。
学习心得:
O(∩_∩)O哈哈~想要算多少式子都行了~~小学低年级同学必备~~