Compare commits

...

25 Commits
v1.0 ... main

Author SHA1 Message Date
array-in-a-matrix 86979c9d54 install/uninstall options 2023-02-07 23:16:34 -05:00
array-in-a-matrix 5583e2ddb8 install/uninstall options 2023-02-07 15:35:06 -05:00
array-in-a-matrix 870de20e20 install/uninstall options 2023-02-07 15:22:11 -05:00
array-in-a-matrix 3d6877c822 install/uninstall options 2023-02-07 08:39:10 -05:00
array-in-a-matrix 97dbc9fb7b space out im num 2023-02-06 15:38:34 -05:00
array-in-a-matrix 16e566bfa0 tui 2023-02-06 15:22:05 -05:00
array-in-a-matrix 5fa84b93fb added space between results 2022-12-06 13:57:48 -05:00
array-in-a-matrix 858990447e removed cringe 2022-10-04 11:48:01 -04:00
array-in-a-matrix 3bb69b067b typo 2022-09-26 18:01:15 -04:00
array-in-a-matrix 56fa33af33 cleaner output 2022-09-26 15:03:42 -04:00
array-in-a-matrix 8180560937 didnt rename tui properly 2021-11-15 19:02:18 -05:00
array-in-a-matrix 366f728cf2 slight improvements 2021-11-05 18:42:58 -04:00
array-in-a-matrix c9a28180bd renamed 2021-11-05 18:34:05 -04:00
array-in-a-matrix 4721f63b25 changed bash to sh 2021-11-05 18:20:51 -04:00
array-in-a-matrix 9a04c7ff2b improved tui integration 2021-11-05 18:20:37 -04:00
array-in-a-matrix d05cb38140 changed binary output name 2021-11-05 18:04:44 -04:00
Array in a Matrix 33f9aff350
Merge pull request #3 from array-in-a-matrix/tui
Tui
2021-11-05 15:02:54 -07:00
array-in-a-matrix 352f3a9472 tui completed 2021-11-05 18:01:13 -04:00
array-in-a-matrix e90ab33dd8 tui bash prompt 2021-11-05 17:54:18 -04:00
array-in-a-matrix 533eb5243e not going to use LTUI 2021-11-05 17:08:47 -04:00
array-in-a-matrix 51a1738e18 commandline parameters support 2021-11-05 17:02:17 -04:00
array-in-a-matrix 6de5afde59 accept command line args 2021-11-05 13:48:55 -04:00
array-in-a-matrix dc49dbf65b changed ui to a dialog 2021-11-05 01:05:18 -04:00
array-in-a-matrix eea5ee0e3f changed ui to a dialog 2021-11-05 01:04:53 -04:00
array-in-a-matrix 63559385e7 base lua tui window 2021-11-05 00:17:50 -04:00
5 changed files with 68 additions and 34 deletions

4
.gitignore vendored
View File

@ -50,3 +50,7 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf
# quadratic executable
quadratic
quadratic-tui

View File

@ -1,5 +1,3 @@
# quadratic
Simple cli calculator that computes real and complex roots of a quadratic.
<br>
Make a project do one thing good rather than do alot that isn't. I learned from my past projects and the best way to code is to KISS.

View File

@ -1,2 +1,12 @@
DESTDIR ?= /usr/bin
all:
gcc quadratic.c -lm -Wall -O3 -o "bin-quadratic.out"
gcc quadratic.c -lm -Wall -O3 -o "quadratic"
cp quadratic-tui.sh quadratic-tui
install:
install -Dm755 quadratic $(DESTDIR)/
install -Dm755 quadratic-tui $(DESTDIR)/
uninstall:
rm -f $(DESTDIR)/{quadratic,quadratic-tui}

27
quadratic-tui.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh
ARG_A=$(whiptail --inputbox "Please enter the value for \"a\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus != 0 ]; then
echo "User cancelled input."
exit
fi
ARG_B=$(whiptail --inputbox "Please enter the value for \"b\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus != 0 ]; then
echo "User cancelled input."
exit
fi
ARG_C=$(whiptail --inputbox "Please enter the value for \"c\":" 10 50 --title "Quadratic Calculator" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus != 0 ]; then
echo "User cancelled input."
exit
fi
quadratic $ARG_A $ARG_B $ARG_C

View File

@ -1,47 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
int main(int num_arg, char **args)
{
system("clear");
printf("\n ~~ Quadratic Calculator ~~\n");
printf(" ̲ ̲ ̲ ̲ ̲ ̲\n");
printf(" ̲-̲b̲±̲√̲b̲̲²̲̲-̲4̲a̲c̲\n");
printf(" 2a\n\n");
double num_A, num_B, num_C;
printf("Please enter the value for \"a\":\n");
scanf("%lf", &num_A);
printf("Please enter the value for \"b\":\n");
scanf("%lf", &num_B);
printf("Please enter the value for \"c\":\n");
scanf("%lf", &num_C);
double radical = pow(num_B, 2) + (-4 * num_A * num_C);
printf("\nUnder the radical: %f\n", radical);
if (radical < 0.0)
if (num_arg <= 1)
{
// roots are complex
printf("Roots are complex.\n");
double real_part = (-num_B) / (2 * num_A);
double imaginary_part = sqrt(radical * -1.0) / (2 * num_A);
printf("The zeros are: %f+%fi and %f-%fi.\n", real_part, imaginary_part, real_part, imaginary_part);
system("quadratic-tui"); // make sure it is in PATH along with "quadratic" bin
}
else
{
// roots are real
printf("Roots are real.\n");
num_A = atof(args[1]);
num_B = atof(args[2]);
num_C = atof(args[3]);
double numerator_1 = (-num_B) + sqrt(radical);
double numerator_2 = (-num_B) - sqrt(radical);
double zero_1_ptr = numerator_1 / (2 * num_A);
double zero_2_ptr = numerator_2 / (2 * num_A);
double radical = pow(num_B, 2) + (-4 * num_A * num_C);
printf("The zeros are: %f and %f.\n", zero_1_ptr, zero_2_ptr);
if (radical < 0.0)
{
// roots are complex
double real_part = (-num_B) / (2 * num_A);
double imaginary_part = sqrt(radical * -1.0) / (2 * num_A);
printf("%g+%gi\t %g-%gi\n", real_part, imaginary_part, real_part, imaginary_part);
}
else
{
// roots are real
double numerator_1 = (-num_B) + sqrt(radical);
double numerator_2 = (-num_B) - sqrt(radical);
double zero_1_ptr = numerator_1 / (2 * num_A);
double zero_2_ptr = numerator_2 / (2 * num_A);
printf("%g\t %g\n", zero_1_ptr, zero_2_ptr);
};
};
return 0;
};