标签:
源码如下:
1 #include <iostream>
2 #include <String>
3 using namespace std;
4
5 int main(int argc, char *argv[])
6 {
7 int a,b; //取输入值变量
8 int sum;//求答案变量
9 int x; //判断+-*/变量
10 cout << "++++++++++++++++++++++++++++++++++++++" << endl;
11 cout << "+ +" << endl;
12 cout << "+ 简易计算器 +" << endl;
13 cout << "+ +" << endl;
14 cout << "++++++++++++++++++++++++++++++++++++++" << endl;
15 cout <<"输入第1个数:";
16 cin >> a;
17 cout <<"输入第2个数:";
18 cin >> b;
19 cout << "①相加" << endl;
20 cout << "②相减" << endl;
21 cout << "③相乘" << endl;
22 cout << "④相除" << endl;
23 cout << "请选择上边操作序号:" ;
24 cin >> x;
25 switch(x)
26 {
27 case 1:
28 {
29 sum=a+b;
30 cout << "两数相加的和为:" << sum << endl;
31 break;
32
33 }
34 case 2:
35 {
36 sum=a-b;
37 cout << "两数相减的差为:" << sum << endl;
38 break;
39 }
40 case 3:
41 {
42 sum=a*b;
43 cout << "两数相乘的积为:" << sum << endl;
44 break;
45
46 }
47 case 4:
48 {
49 sum=a/b;
50 cout << "两数相除的商为:" << sum << endl;
51 break;
52
53 }
54
55
56
57 }
58
59 cin.get();
60 return 0;
61 }
笔记:
cin 输入
switch case 多条件判断
标签:
原文地址:http://www.cnblogs.com/hkleak/p/4853360.html