Directory Listing | |
---|---|
arrays_lab_session1.cpp
|
|
arrays_lab_session2.cpp
|
|
example.cpp
|
|
labD_pseudo_code.txt
|
|
switch_dowhile_example.cpp
|
|
switch_example.cpp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
int main() {
char option,
repeat;
int x, y;
cout << "Welcome! Here are options:\n";
cout << " 1 - Addition\n 2 - Subtraction\n 3 - Multiplication\n 4 - Division" << endl;
cin >> option;
cout << "Input x: ";
cin >> x;
cout << "Input y: ";
cin >> y;
switch (option) {
case '1':
//Addition
cout << x << " + " << y << " = " << x + y << endl;
break;
case '2':
//Subtraction
cout << x << " - " << y << " = " << x - y << endl;
break;
case '3':
//Multiplcation
cout << x << " * " << y << " = " << x * y << endl;
break;
case '4':
//Division
cout << x << " / " << y << " = " << (double)x / y << endl;
break;
default:
cout << "You broke it." << endl;
break;
}
}