Calculator Microproject Final Report
Calculator Microproject Final Report
1. Introduction
A calculator is an essential tool in mathematics, science, and daily life. This microproject aims to
develop a simple calculator using C that can perform basic arithmetic operations such as addition,
subtraction, multiplication, and division. The project helps in understanding loops, switch-case
statements, and user input handling. By implementing a menu-driven system, users can interact
dynamically with the program. This project serves as a foundation for learning programming and can
be extended into more advanced applications like scientific calculators or financial tools.
2. Objectives
- Develop a menu-driven calculator in C.
3. Problem Definition
A simple command-line calculator is needed to perform arithmetic operations based on user input.
The calculator should take two numbers, perform the selected operation, and display the result. It
should also handle errors like division by zero and invalid inputs. Continuous execution should be
ensured to allow multiple calculations without restarting. The program should be user-friendly,
providing clear prompts and messages.
4. Algorithm
Step 1: Start
Step 9: End
- Check how the program handles invalid inputs like characters instead of numbers.
- Debug and fix logical errors, input validation, and precision issues.
6. Conclusion
The calculator microproject successfully implements a simple arithmetic calculator using C. It
error handling. The project allows multiple calculations without restarting and provides a
user-friendly experience. This project serves as a strong foundation for learning C programming and
7. Source Code
#include <stdio.h>
void calculator() {
int choice;
double num1, num2, result;
do {
printf("\n--- Simple Calculator ---\n");
printf("1. Addition (+)\n");
printf("2. Subtraction (-)\n");
printf("3. Multiplication (*)\n");
printf("4. Division (/)\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
result = num1 + num2;
printf("Result: %.2lf + %.2lf = %.2lf\n", num1, num2, result);
break;
case 2:
result = num1 - num2;
printf("Result: %.2lf - %.2lf = %.2lf\n", num1, num2, result);
break;
case 3:
result = num1 * num2;
printf("Result: %.2lf * %.2lf = %.2lf\n", num1, num2, result);
break;
case 4:
if (num2 != 0) {
result = num1 / num2;
printf("Result: %.2lf / %.2lf = %.2lf\n", num1, num2, result);
} else {
printf("Error: Division by zero!\n");
}
break;
case 5:
printf("Exiting...\n");
break;
default:
printf("Invalid choice!\n");
}
} while (choice != 5);
}
int main() {
calculator();
return 0;
}
8. Expected Output
Example Execution:
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Exit