Government Polytechnic Ahemadnagar
Academic Year: 2024-25
Report
On
Micro Project
TITLE:
SIMPLE CALCULATOR IN C
- PROGRAM: COMPUTER ENGINEERING
- COURSE NAME: Programming in C
- COURSE CODE: 2201
Submitted by:
Student Name: [Your Name]
Under The Guidance of:
Faculty: [Teacher's Name]
Certificate
This is to certify that Mr./Ms. [Your Name] of Third Semester Diploma in Computer Engineering has
completed the Microproject satisfactorily in Programming in C for the academic year 2024-25 as
prescribed in the curriculum.
1.0) Introduction
A calculator is an essential tool for performing mathematical operations. This project implements a
basic calculator in C that performs arithmetic operations like addition, subtraction, multiplication, and
division.
2.0) Objectives
- Develop a menu-driven calculator in C.
- Allow users to perform basic arithmetic operations.
- Ensure error handling (e.g., division by zero).
3.0) Problem Definition
A command-line calculator is needed that can accept two numbers from the user and perform the
desired operation.
4.0) Algorithm
Step 1: Start
Step 2: Display menu options
Step 3: Take user input for operation choice
Step 4: Input two numbers
Step 5: Perform the selected arithmetic operation
Step 6: Display the result
Step 7: Ask if the user wants to continue
Step 8: Repeat or exit based on user choice
Step 9: End
5.0) 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);
if (choice >= 1 && choice <= 4) {
printf("Enter first number: ");
scanf("%lf", &num1);
printf("Enter second number: ");
scanf("%lf", &num2);
}
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;
}
6.0) Testing & Debugging
- Test different inputs and verify correct results.
- Ensure division by zero is handled correctly.
- Test invalid inputs (e.g., characters instead of numbers).
7.0) Enhancements & Future Scope
- Implement more operations like exponentiation.
- Develop a graphical interface for the calculator.
- Allow users to store previous calculations.
8.0) Applications
- Useful for performing basic arithmetic calculations.
- Can be used in embedded systems for quick calculations.
9.0) Conclusion
The microproject successfully implements a simple calculator in C that performs arithmetic
operations efficiently. It demonstrates the use of loops, switch-case statements, and error handling.