Skip to content

Commit

Permalink
Remove executable file and rename directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
dohoudaniel committed Aug 8, 2023
1 parent 2b3e297 commit 13ea576
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
50 changes: 50 additions & 0 deletions collins331/Calculator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/**
*main - performs simple arithmetic operation
*Return: 0(success)
*/
int main(void)
{
double num1, num2, Result;
char operator;

printf("Enter your first number:\n");
if ((scanf("%lf", &num1) != 1))
{
printf("You entered invalid first number !!\n");
exit(-1);
}
printf("Enter your second number:\n");
if (scanf("%lf", &num2) != 1)
{
printf("You entered invalid number above !!\n");
exit(-1);
}
printf("Please enter your arithmetic operator:\n");
printf("Allowed operators are: (/), (*), (+), (-)\n");
scanf("%s", &operator);
switch (operator)
{
case '+':
Result = num1 + num2;
printf("%.2f\n", Result);
break;
case '-':
Result = num1 - num2;
printf("%.2f\n", Result);
break;
case '*':
Result = num1 * num2;
printf("%.2f\n", Result);
break;
case '/':
printf("%.2f\n", Result = num1 / num2);
break;
default:
printf("Arithmetic error, try again\n");
break;
}
return (0);
}
26 changes: 26 additions & 0 deletions collins331/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# CALCULATOR DEMO PROJECT

* This is a simple calculator that performs simple arithmetic operations for:
* Addition(+)
* Subtraction (-)
* Multiplication(*)
* Division(/)
* The Calculator is built in C programming language.

### How to Use the Calculator:

1. Compile the Calculator.c file using:
```
gcc -Wall -pedantic -Werror -Wextra -std=gnu89 Calculator.c -o Calculator
```
To run the executable file generated:

```
./Calculator
```
- The Calculator will prompt the user to enter the first number
- Next prompt will be for the second number

- Finally, it'll prompt the user to enter the allowed arithmetic operator

## ENJOY THE USE

0 comments on commit 13ea576

Please sign in to comment.