0

While analyzing can't seem to avoid the value stored to 'delta' not being read... what part of my loop isn't working and why?

#include <stdio.h>
#include <math.h>
int main()
{
    float a, b, c;
    float delta;
    printf("a=");
    scanf("%f", &a);
    printf("b=");
    scanf("%f", &b);
    printf("c=");
    scanf("%f", &c);
    float x, x1, x2;
    delta=((b*b)-(4*a*c));
    if("delta==0")
    {
        x=((-b)/(2*a));
        printf("x=%f \n", x);
    }
    else if("delta>0")
    {
        x1=((-b+sqrt(delta))/(2*a));
        x2=((-b-sqrt(delta))/(2*a));
        printf("x1=%f i x2=%f \n", x1, x2);
    }
    else printf("Nie ma w zbiorze liczb rzeczywistych rozwiazania tego rownania.\n");
    return 0;
}
Kat Navara
  • 11
  • 2

1 Answers1

0

1st thing, if("delta==0") inside "" whatever is present that will be treated as a address so if(address) means true, remove the double quotation.

if(delta==0)
    // some code
 else if (delta > 0)
    // some code

2nd thing, you are comparing(==) a float & an integer, so be aware of behaviour of comparing different operands.

Achal
  • 11,821
  • 2
  • 15
  • 37