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.
Remove executable file and rename directory.
- Loading branch information
1 parent
2b3e297
commit 13ea576
Showing
2 changed files
with
76 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 |
---|---|---|
@@ -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); | ||
} |
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,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 |