how to make a calculator inc++

// ONLY 29 LINES OF CODE IN TOTAL
// For better calculator scroll down on this post
#include <iostream>
using namespace std;
int main() {
	cout << "Please enter the first number: ";
	double n1 = 0;
	cin >> n1;
	cout << "Please enter an operator (+, -, *, /): ";
	char op = '0';
	cin >> op;
	cout << "Please enter a second number: ";
	double n2 = 0;
	cin >> n2;
	double answer = 0;
	switch (op) {
	case '+': 
		answer = n1 + n2;
		break;
	case '-':
		answer = n1 - n2;
		break;
	case '*': 
		answer = n1 * n2;
		break;
	case '/': 
		answer = n1 / n2;
		break;
	}
	cout << "Thanks for using my calculator your answer is: " << answer;
  
  // this is the better calculator:
  
  #include <iostream>
#include <Windows.h>
using namespace std;
int main() {
	char jim = 'j';
	do {
		
		cout << "Please enter the first number: ";
		double n1 = 0;
		cin >> n1;
		cout << "Please enter an operator (+, -, *, /): ";
		char op = '0';
		cin >> op;
		cout << "Please enter a second number: ";
		double n2 = 0;
		cin >> n2;
		double answer = 0;
		switch (op) {
		case '+':
			answer = n1 + n2;
			break;
		case '-':
			answer = n1 - n2;
			break;
		case '*':
			answer = n1 * n2;
			break;
		case '/':
			answer = n1 / n2;
			break;
		}
		cout << "Thanks for using my calculator your answer is: " << answer << " do you want to run the program again? (y or n) ";
		cin >> jim;

	} while (jim = 'y' && jim != 'n');
	if (jim = 'n') {
		cout << "Thanks for using my calculator here is sum epic music";
		Beep(329, 300);
		Beep(493, 300);
		Beep(698, 300);
		Beep(659, 600);

		Beep(783, 300);
		Beep(698, 300);
		Beep(659, 600);

		Beep(329, 100);
		Beep(493, 300);
		Beep(698, 300);
		Beep(659, 600);

		Beep(392, 250);
		Beep(440, 200);
		Beep(587, 300);

		Beep(349, 250);
		Beep(587, 500);

		Beep(329, 300);
		Beep(493, 300);
		Beep(698, 300);
		Beep(659, 600);

		Beep(783, 300);
		Beep(698, 300);
		Beep(659, 600);

		Beep(329, 100);
		Beep(493, 300);
		Beep(698, 300);
		Beep(659, 600);

		Beep(392, 250);
		Beep(440, 200);
		Beep(587, 300);

		Beep(349, 250);
		Beep(587, 400);
	}
	return 0;
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source