Mercurial Hosting > quickcalc
changeset 0:9bf878c59a1d
Finished
author | VilyaemKenyaz |
---|---|
date | Fri, 25 Aug 2023 13:42:00 -0400 |
parents | |
children | dfce17cc481b |
files | README.md c.ksh quickcalc quickcalc.c |
diffstat | 4 files changed, 50 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Fri Aug 25 13:42:00 2023 -0400 @@ -0,0 +1,17 @@ +# QUICKCALC +Quickcalc is a program that is a simple integer based calculator, here are the +operators: +1 - Add +2 - Subtract +3 - Multiply +4 - Divide + +Example of usage: + +1 + 1 = 2 + +quickcalc 1 1 1 + +5 * 2 = 10 + +quickcalc 5 3 2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c.ksh Fri Aug 25 13:42:00 2023 -0400 @@ -0,0 +1,6 @@ +#!/bin/ksh +clear +printf "Compiling\n" +rm quickcalc +tcc quickcalc.c -o quickcalc +cp quickcalc /usr/bin/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/quickcalc.c Fri Aug 25 13:42:00 2023 -0400 @@ -0,0 +1,27 @@ +// A simple calculator, if no arguments do wizard mode. + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <math.h> + +int main(int argc, char* argv[]){ + + if (argc == 1) { puts("Quickcalculator 1Add 2Sub 3Mul 4Div"); exit(1);} + // Get numbers + unsigned int value1 = atoi(argv[1]); + unsigned int value2 = atoi(argv[3]); + + // Determine operation + unsigned int operation = atoi(argv[2]); // addition subtraction multiplication division + // Do calculation and print + int finalvalue; + + if (operation == 1){finalvalue = value1 + value2;} + if (operation == 2){finalvalue = value1 - value2;} + if (operation == 3){finalvalue = value1 * value2;} + if (operation == 4){finalvalue = value1 / value2;} + + printf("%d\n", finalvalue); + exit(0); +}