forked from ALX-SE-Algorithmia/Demo-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
668865c
commit 45df154
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.vscode | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Introduction to a Simple Calculator | ||
|
||
## Description | ||
|
||
This is a simple calculator that can perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It is written in C programming language. | ||
|
||
## Technologies | ||
|
||
- C programming language |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include <stdio.h> | ||
|
||
/* | ||
- a,b are the operands | ||
- op is the operator | ||
*/ | ||
int main(void) | ||
{ | ||
int a, b; | ||
char op; | ||
printf("\n======================= Welcome to my simple Calculator 💻 ===========================\n\n"); | ||
printf("A few rules before we start 📝:\n\n"); | ||
printf("1. The program only accepts math expressions and numbers \n"); | ||
printf("2. The program only accepts numbers that are less than 2147483647\n"); | ||
printf("3. The program only accepts the following operators: +, -, *, / and %%\n"); | ||
printf("4. The program will print an error message if the user enters an invalid operator\n\n"); | ||
printf("\t A correct format is shown 👉 Eg: 6 + 3 = 9\n\n"); | ||
|
||
|
||
printf("\nEnter an expression: "); | ||
scanf("%d %c %d", &a, &op, &b); | ||
switch (op) | ||
{ | ||
case '+': | ||
printf("Result: %d\n", a + b); | ||
break; | ||
case '-': | ||
printf("Result: %d\n", a - b); | ||
break; | ||
case '*': | ||
printf("Result: %d\n", a * b); | ||
break; | ||
case '/': | ||
printf("Result: %d\n", a / b); | ||
break; | ||
default: | ||
printf("Invalid operator\n"); | ||
printf("Eg: 6 + 3\n"); | ||
break; | ||
} | ||
return 0; | ||
} |