-1

Currently practicing on how to make a script for calculating using the quadratic formula, and it seems that I always get stuck on this output:

Input the first number(a): 11

Input the second number(b): -4

Input the third number(c): -4

 What mode do you choose?
[1]: Complex Mode
[2]: Normal Mode 1

Not a single thing coming from the print statements and I have no error returned to me, what should i do? Even if rewrote all the code from scratch and using what ever libs i can find that might help, installed and removed clang for whatever reason...

#include <stdio.h>
#include <math.h>
#include <complex.h>
#include <tgmath.h>
int main()
{
    int choice;
    double z1, z2, delta, a, b, c, pr1;
    printf("\nInput the first number(a): ");
    scanf("%lf", &a);
    printf("\nInput the second number(b): ");
    scanf("%lf", &b);
    printf("\nInput the third number(c): ");
    scanf("%lf", &c);

    printf("\n What mode do you choose? \n[1]: Complex Mode \n[2]: Normal Mode ");
    scanf("%d", choice);

    if (choice == 1)
    {
        printf("... \n Complex Mode \n [ON!]");
        delta = pow(b, 2) - (4 * a * c);
        printf("%d", delta);

        if (delta < 0 && a != 0)
        {
            delta = sqrt(delta);
            z1 = (-b - (I * (-delta)) / (2 * a));
            z2 = conj(z1);
            printf("Root1 = %.5lf\n", z1);
            printf("Root2 = %.5lf\n", z2);
        }
        else
        {
            printf("\nImpossible to find the roots.\n");
        }
    }
    else if (choice == 2)
    {
        printf("Normal mode is ON");

        pr1 = (b * b) - (4 * (a) * (c));

        if (pr1 > 0 && a != 0)
        {
            double x, y;
            pr1 = sqrt(pr1);
            x = (-b + pr1) / (2 * a);
            y = (-b - pr1) / (2 * a);
            printf("Root1 = %.5lf\n", x);
            printf("Root2 = %.5lf\n", y);
        }
        else
        {
            printf("\nImpossible to find the roots.\n");
        }
    }

    return 0;
}
Lindgrei
  • 3
  • 1
  • 3
    Compiler warnings [are your friends](https://stackoverflow.com/questions/57842756/why-should-i-always-enable-compiler-warnings). – n. m. could be an AI May 07 '22 at 17:44
  • The compilers gcc and clang will both provide a warning when compiling your posted code, which points out in which line the error is. However, with gcc, you must compile with the `-Wall` command-line option to enable the warning, with clang this is not necessary, as that warning is enabled by default. – Andreas Wenzel May 07 '22 at 18:12

1 Answers1

2

As someone already pointed out, check your warnings. For instance the lines:

scanf("%d", choice);
printf("%d", delta); 

should read

scanf("%d", &choice);
printf("%f", delta);
Bartender1382
  • 195
  • 1
  • 10