Skip to content

Commit

Permalink
flexywork327 simple calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
flexywork327 committed Aug 11, 2023
1 parent 668865c commit 45df154
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
.DS_Store
9 changes: 9 additions & 0 deletions flexywork327/README.md
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 added flexywork327/main
Binary file not shown.
44 changes: 44 additions & 0 deletions flexywork327/main.c
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;
}

0 comments on commit 45df154

Please sign in to comment.