Skip to content

Commit

Permalink
max calc;
Browse files Browse the repository at this point in the history
  • Loading branch information
odoh-tc committed Aug 2, 2023
1 parent df1ba17 commit 3bf7069
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
61 changes: 61 additions & 0 deletions maximo/cal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <stdio.h>

/**
* main - main function
* Return: 0
*/


int main(void)
{
char operator;
float a;
float b;
float result;


printf("\nEnter an operator(-, +, *, /): ");
scanf("%c", &operator);

printf("\nEnter number1: ");
scanf("%f", &a);

printf("\nEnter number2: ");
scanf("%f", &b);



switch(operator)
{
case '+':
result = a + b;
printf("\nresult is: %.2f\n", result);
break;

case '-':
result = a - b;
printf("\nresult is: %.2f\n", result);
break;

case '*':
result = a * b;
printf("\nresult is: %.2f\n", result);
break;

case '/':
if (b != 0)
{
result = a / b;
printf("\nresult is: %.2f\n", result);
}
else
{
printf("\nnumber cannot be divided by zero\n");
}
break;

default:
printf("%c is not valid\n", operator);
}
return (0);
}
15 changes: 15 additions & 0 deletions maximo/max.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Implementation of a simple Calculator in C programming.

This is my implementation of the calculator. It performs a simple opeeration like multplication, division, subtraction and addition.

Example

$ gcc *.c -o cal
$ ./cal
Enter an operator(-, +, *, /): *

Enter number1: 7

Enter number2: 6

result is: 13.00

0 comments on commit 3bf7069

Please sign in to comment.