Skip to content

Commit

Permalink
Merge pull request #52 from Manuelshub/manuelsbranch
Browse files Browse the repository at this point in the history
Contribution to Demo Project
  • Loading branch information
MartyOfMCA authored Aug 1, 2023
2 parents 9e565de + 9fc93ee commit 4222b01
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
9 changes: 9 additions & 0 deletions manuelshub/README.md
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 - (-)
13 changes: 13 additions & 0 deletions manuelshub/calc.h
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
69 changes: 69 additions & 0 deletions manuelshub/main.c
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);
}
65 changes: 65 additions & 0 deletions manuelshub/operations.c
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);
}
}

0 comments on commit 4222b01

Please sign in to comment.