how to make a calculator inc 2b 2b

Solutions on MaxInterview for how to make a calculator inc 2b 2b by the best coders in the world

showing results for - "how to make a calculator inc 2b 2b"
Robin
30 Jan 2017
1// ONLY 29 LINES OF CODE IN TOTAL
2// For better calculator scroll down on this post
3#include <iostream>
4using namespace std;
5int main() {
6	cout << "Please enter the first number: ";
7	double n1 = 0;
8	cin >> n1;
9	cout << "Please enter an operator (+, -, *, /): ";
10	char op = '0';
11	cin >> op;
12	cout << "Please enter a second number: ";
13	double n2 = 0;
14	cin >> n2;
15	double answer = 0;
16	switch (op) {
17	case '+': 
18		answer = n1 + n2;
19		break;
20	case '-':
21		answer = n1 - n2;
22		break;
23	case '*': 
24		answer = n1 * n2;
25		break;
26	case '/': 
27		answer = n1 / n2;
28		break;
29	}
30	cout << "Thanks for using my calculator your answer is: " << answer;
31  
32  // this is the better calculator:
33  
34  #include <iostream>
35#include <Windows.h>
36using namespace std;
37int main() {
38	char jim = 'j';
39	do {
40		
41		cout << "Please enter the first number: ";
42		double n1 = 0;
43		cin >> n1;
44		cout << "Please enter an operator (+, -, *, /): ";
45		char op = '0';
46		cin >> op;
47		cout << "Please enter a second number: ";
48		double n2 = 0;
49		cin >> n2;
50		double answer = 0;
51		switch (op) {
52		case '+':
53			answer = n1 + n2;
54			break;
55		case '-':
56			answer = n1 - n2;
57			break;
58		case '*':
59			answer = n1 * n2;
60			break;
61		case '/':
62			answer = n1 / n2;
63			break;
64		}
65		cout << "Thanks for using my calculator your answer is: " << answer << " do you want to run the program again? (y or n) ";
66		cin >> jim;
67
68	} while (jim = 'y' && jim != 'n');
69	if (jim = 'n') {
70		cout << "Thanks for using my calculator here is sum epic music";
71		Beep(329, 300);
72		Beep(493, 300);
73		Beep(698, 300);
74		Beep(659, 600);
75
76		Beep(783, 300);
77		Beep(698, 300);
78		Beep(659, 600);
79
80		Beep(329, 100);
81		Beep(493, 300);
82		Beep(698, 300);
83		Beep(659, 600);
84
85		Beep(392, 250);
86		Beep(440, 200);
87		Beep(587, 300);
88
89		Beep(349, 250);
90		Beep(587, 500);
91
92		Beep(329, 300);
93		Beep(493, 300);
94		Beep(698, 300);
95		Beep(659, 600);
96
97		Beep(783, 300);
98		Beep(698, 300);
99		Beep(659, 600);
100
101		Beep(329, 100);
102		Beep(493, 300);
103		Beep(698, 300);
104		Beep(659, 600);
105
106		Beep(392, 250);
107		Beep(440, 200);
108		Beep(587, 300);
109
110		Beep(349, 250);
111		Beep(587, 400);
112	}
113	return 0;
114}