1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Calculate the real roots of a quadratic equation

  1. Apr 10, 2006 #1
    Please Help!

    I designed this "PROGRAM"!!! TO calculate the real roots of a quadratic equation....

    but the compiler miracle C kept saying there's something wrong around the "if" word.... saying "unrecognised types in comparison"
    it seem SO FINE to me.... what is wrong?!?!?!?!?!:eek:

    #include <stdio.h>
    #include <math.h>

    int main(void)
    /* Declare variables. */
    double a,b,c,d,e,f;

    printf("This program computes the real roots of a quadratic equations.\n");
    printf("(recall that the general form of quadratic equation is ax^2+bx+c where a, b and c are canstants)\n");

    printf("please enter the first coefficient.\n");
    scanf("%f", &a);

    printf("please enter the second coefficient.\n");
    scanf("%f", &b);

    printf("please enter the third coefficient.\n");
    scanf("%f", &c);


    printf("roots are not real.\n");

    printf("%f, %f",d,e);

    /* Exit program. */
    return 0;
    Last edited: Apr 10, 2006
  2. jcsd
  3. Apr 10, 2006 #2
    1. To read doubles, use %lf in scanf().
    2. You will need braces around the else body.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook