-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from Manuelshub/manuelsbranch
Contribution to Demo Project
- Loading branch information
Showing
4 changed files
with
156 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,9 @@ | ||
This is a basic C Calculator | ||
-------------- | ||
This Calculator takes input(digits and an arithmetic operator) from the user and performs an Arithmetic operation. | ||
|
||
PERMITTED OPERATORS | ||
Addition - (+) | ||
Subtraction - (-) | ||
Multiplication - (*) | ||
Division - (-) |
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,13 @@ | ||
/*This file contains Function prototypes or declaration*/ | ||
#ifndef CALC_H | ||
#define CALC_H | ||
|
||
#include <stdio.h> /* Standard Input and Output header file*/ | ||
#include <unistd.h> | ||
|
||
double add(double a, double b); | ||
double sub(double a, double b); | ||
double mul(double a, double b); | ||
double div(double a, double b); | ||
|
||
#endif |
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,69 @@ | ||
#include "calc.h" | ||
|
||
int main() | ||
{ | ||
double num1, num2, result; | ||
char operator; | ||
|
||
sleep(1.5); | ||
printf("\tHi there!!\n"); | ||
sleep(2.75); | ||
printf("\tYou're most Welcome to use our CALCULATOR!!\n"); | ||
sleep(2.75); | ||
printf("\nPERMITTED OPERATORS:\n"); | ||
sleep(2.5); | ||
printf("For Addition (+)\n"); | ||
sleep(2); | ||
printf("For Subtraction (-)\n"); | ||
sleep(2); | ||
printf("For Multiplication (*)\n"); | ||
sleep(2); | ||
printf("For Division (/)\n"); | ||
sleep(2); | ||
printf("\nEnter The first number-->> "); | ||
scanf("%2lf", &num1); | ||
sleep(1.5); | ||
printf("Enter the second number-->> "); | ||
scanf("%2lf", &num2); | ||
sleep(1.5); | ||
printf("Enter the arithmetic sign:"); | ||
scanf(" %c", &operator); | ||
sleep(1.5); | ||
|
||
switch(operator) | ||
{ | ||
case '+': | ||
result = add(num1, num2); | ||
break; | ||
|
||
case '-': | ||
result = sub(num1, num2); | ||
break; | ||
|
||
case '*': | ||
result = mul(num1, num2); | ||
break; | ||
|
||
case '/': | ||
result = div(num1, num2); | ||
break; | ||
|
||
default: | ||
printf("Invalid Operator!!\n\n"); | ||
return (1); | ||
} | ||
if (operator == '/' && num2 == 0) | ||
{ | ||
sleep(1.5); | ||
printf("Recompile to use again!\n\n"); | ||
} | ||
else | ||
{ | ||
sleep(1.5); | ||
printf("\nThe result is %2lf\n", result); | ||
sleep(3); | ||
printf("Recompile to use again!\n\n"); | ||
} | ||
|
||
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,65 @@ | ||
#include "calc.h" | ||
|
||
/** | ||
* add - Function that adds two numbers | ||
* @a: the first parameter | ||
* @b:the second parameter | ||
* Return: The sum of both numbers | ||
*/ | ||
|
||
double add(double a, double b) | ||
{ | ||
double sum; | ||
sum = a + b; | ||
return (sum); | ||
} | ||
|
||
/** | ||
* sub - Funtiion that takes two numbers as parameter and return their difference | ||
* @a: the first parameter | ||
* @b: the second parameter | ||
* Return: the difference of the two numbers | ||
*/ | ||
|
||
double sub(double a, double b) | ||
{ | ||
double minus; | ||
minus = a - b; | ||
return (minus); | ||
} | ||
|
||
/** | ||
* mul - Function that multiplies two numbers | ||
* @a: first parameter | ||
* @b: second parameter | ||
* Return: the product of the two numbers | ||
*/ | ||
|
||
double mul(double a, double b) | ||
{ | ||
double prod; | ||
prod = a * b; | ||
return (prod); | ||
} | ||
|
||
/** | ||
* div - Function that divides two numbers | ||
* @a: first parameter | ||
* @b: second parameter | ||
* Return: The division of the two numbers | ||
*/ | ||
|
||
double div(double a, double b) | ||
{ | ||
double c; | ||
if (b == 0) | ||
{ | ||
printf("Error: Denominator cannot be Zero!\n"); | ||
return(0.00); | ||
} | ||
else | ||
{ | ||
c = a / b; | ||
return (c); | ||
} | ||
} |