sachinverma2406 / cpp

0 stars 0 forks source link

calculator #2

Open sachinverma2406 opened 6 days ago

sachinverma2406 commented 6 days ago

simple C++ program for a calculator that performs basic operations like addition, subtraction, multiplication, and division. It uses a menu-driven approach, where the user can choose which operation to perform:

sachinverma2406 commented 6 days ago

How It Works: Input: The program asks for two numbers and an operator (+, -, *, /). Operation Selection: Using a switch statement, it performs the operation based on the chosen operator. Error Handling: For division, the program checks if the divisor is zero to prevent division by zero errors. Looping: The do-while loop allows the user to perform multiple calculations by asking if they want to continue (y to continue or n to exit).

Enter first number: 10 Enter an operator (+, -, , /): Enter second number: 5 Result: 50 Do you want to perform another calculation? (y/n): y Enter first number: 15 Enter an operator (+, -, *, /): / Enter second number: 0 Error: Division by zero is not allowed. Do you want to perform another calculation? (y/n): n Calculator closed. Thank you!

sachinverma2406 commented 6 days ago

This code provides a basic, interactive calculator with support for error handling and looping, which can be expanded with more operations if needed!