improved tui integration
This commit is contained in:
parent
d05cb38140
commit
9a04c7ff2b
2 changed files with 53 additions and 31 deletions
50
quadratic.c
50
quadratic.c
|
@ -9,46 +9,34 @@ int main(int num_arg, char **args)
|
||||||
|
|
||||||
if (num_arg <= 1)
|
if (num_arg <= 1)
|
||||||
{
|
{
|
||||||
|
system("/bin/sh ./tui.sh");
|
||||||
system("clear");
|
|
||||||
printf("\n ~~ Quadratic Calculator ~~\n");
|
|
||||||
printf(" ̲ ̲ ̲ ̲ ̲ ̲\n");
|
|
||||||
printf(" ̲-̲b̲±̲√̲b̲̲²̲̲-̲4̲a̲c̲\n");
|
|
||||||
printf(" 2a\n\n");
|
|
||||||
|
|
||||||
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);
|
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
num_A = atof(args[1]);
|
num_A = atof(args[1]);
|
||||||
num_B = atof(args[2]);
|
num_B = atof(args[2]);
|
||||||
num_C = atof(args[3]);
|
num_C = atof(args[3]);
|
||||||
};
|
|
||||||
double radical = pow(num_B, 2) + (-4 * num_A * num_C);
|
|
||||||
|
|
||||||
if (radical < 0.0)
|
double radical = pow(num_B, 2) + (-4 * num_A * num_C);
|
||||||
{
|
|
||||||
// roots are complex
|
|
||||||
double real_part = (-num_B) / (2 * num_A);
|
|
||||||
double imaginary_part = sqrt(radical * -1.0) / (2 * num_A);
|
|
||||||
|
|
||||||
printf("%f+%fi %f-%fi\n", real_part, imaginary_part, real_part, imaginary_part);
|
if (radical < 0.0)
|
||||||
}
|
{
|
||||||
else
|
// roots are complex
|
||||||
{
|
double real_part = (-num_B) / (2 * num_A);
|
||||||
// roots are real
|
double imaginary_part = sqrt(radical * -1.0) / (2 * num_A);
|
||||||
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("%f %f\n", zero_1_ptr, zero_2_ptr);
|
printf("%f+%fi %f-%fi\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("%f %f\n", zero_1_ptr, zero_2_ptr);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
34
tui.sh
Executable file
34
tui.sh
Executable file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/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 "a =" $ARG_A
|
||||||
|
else
|
||||||
|
echo "User canceled 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 "b =" $ARG_B
|
||||||
|
else
|
||||||
|
echo "User canceled 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 "c =" $ARG_C
|
||||||
|
else
|
||||||
|
echo "User canceled input."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
|
||||||
|
./quadratic $ARG_A $ARG_B $ARG_C
|
Loading…
Add table
Reference in a new issue