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.
- Loading branch information
akellomick
committed
Aug 8, 2023
1 parent
5379236
commit 2a9f66c
Showing
8 changed files
with
122 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,13 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* add - ands x and y. | ||
* @x: num1 to compute. | ||
* @y: num2 to compute. | ||
* | ||
* Return: result of x+y. | ||
*/ | ||
int add(int x, int y) | ||
{ | ||
return (x + y); | ||
} |
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 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* div - divides x by y. | ||
* @x: num 1 to compute. | ||
* @y: num2 to compute. | ||
* | ||
* Return: result of x/y | ||
*/ | ||
int div(int x, int y) | ||
{ | ||
return (x / y); | ||
} |
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,8 @@ | ||
#include <stdio.h> | ||
#include "main.h" | ||
|
||
void end_msg() | ||
{ | ||
printf("Sorry, Invalid input - please try again with the corrcet input\n"); | ||
printf("***********************************************************************\n"); | ||
} |
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,45 @@ | ||
#include <stdio.h> | ||
#include "main.h" | ||
|
||
/** | ||
* main - Entry point to program calc. | ||
* | ||
* Return: 0 success, else 1. | ||
*/ | ||
/* Algorithmia Calculator probation project @akellomick*/ | ||
int main(void) | ||
{ | ||
char sign; | ||
int num1; | ||
int num2; | ||
|
||
msg(); | ||
printf("insert a valid arithmetic sign\t"); | ||
scanf("%c", &sign); | ||
printf("Insert first digit\t"); | ||
scanf("%d", &num1); | ||
printf("insert second digit\t"); | ||
scanf("%d", &num2); | ||
|
||
|
||
switch (sign) | ||
{ | ||
case '+': | ||
printf("\t%d + %d = %d\n", num1, num2, add(num1, num2)); | ||
break; | ||
case '-': | ||
printf("\t%d - %d = %d\n", num1, num2, sub(num1, num2)); | ||
break; | ||
case '*': | ||
printf("\t%d * %d = %d\n", num1, num2, mul(num1, num2)); | ||
break; | ||
case '/': | ||
printf("\t%d / %d = %d\n", num1, num2, div(num1, num2)); | ||
break; | ||
|
||
default: | ||
end_msg(); | ||
} | ||
|
||
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,6 @@ | ||
int mul(int x, int y); | ||
int div(int x, int y); | ||
void msg(void); | ||
int add(int x, int y); | ||
int sub(int x, int y); | ||
void end_msg(void); |
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,11 @@ | ||
#include <stdio.h> | ||
#include "main.h" | ||
|
||
void msg() | ||
{ | ||
printf("**********************************************************************\n"); | ||
printf("***********************Algorthimia Calculator**************************\n"); | ||
printf("Insert two numbers alongside a valid arithmetic sign(+-*/) to compute\n"); | ||
printf("\n"); | ||
printf("**********************************************************************\n"); | ||
} |
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 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* mul - multiplies x and y. | ||
* @x: num1 to compute. | ||
* @y: num2 to compute. | ||
* | ||
* Return: result of x*y | ||
*/ | ||
int mul(int x, int y) | ||
{ | ||
return (x * y); | ||
} |
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 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* sub - subtracts y from x. | ||
* @x: num1 to compute. | ||
* @y: num2 to compute. | ||
* | ||
* Return: result of x-y | ||
*/ | ||
int sub(int x, int y) | ||
{ | ||
return (x - y); | ||
} |