Re: Help. Where is my error?




"Red Dragon" <tskhoon@xxxxxxxxxxxx> wrote in message
>news:4353ae06_1@xxxxxxxxxxxxxxxxx
>I am self study C student. I got stuck in the program below on quadratic
equation and will be >most grateful if someone could help me to unravel the
mystery.
>Why does the computer refuse to execute my scanf ("%c",&q);
>On input 3 4 1 (for a,b and c) I had real roots OK
>On input 1 8 16 I had same real roots OK.

>However on 4 2 5, (for imaginary roots ) the computer cannot see the
scanf ("%c",&q); >statement. It just jumps over it.
>How can I make the computer not to ignore this statement? I am on Visual
C++ platform.
>Thanks
>Khoon.

>/* Roots of a Quadratic Equation.
> 12.10.05 */

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

>int main (void)

>{
>int a; int b; int c; float x1; float x2; int E; int E1; float R; float
I;float S;
>char p; char q; char y;

>printf ("Please key in the value of constant a,b and c for finding the
roots of quadratic");
> printf ("equation ax%c+bx+c=0 :",253);
>scanf ("%d%d%d", &a,&b,&c);

> E =(b*b)-(4*a*c);

> if ( E > 0)
> {
> x1 = (float)(-b+sqrt(E))/(2*a);
> x2 = (float)(-b-sqrt(E))/(2*a);

> printf ("\nYour quadratic equation has two distinct real roots: x1=%1.6f
,x2=%1.6f",x1,x2);
> }

> else if (E == 0)
> {

> x1 = (float)(-b+sqrt(E))/(2*a);

> printf ("\nYour quadratic equation has two same: x1=x2=%1.6f\n",x1);
> }

> else
> {

> p = 'y';

> printf ("Your quadratic equation has two distinct imaginary roots. Do
you want to know\n");
> printf ("the values of the imaginary roots (Y/N)?");

/********************************************************
fflush (stdin );
/********************************************************
> scanf ("%c",&q);

> printf ("\nq = %c\n",q);/* Test statement*/
/snip>


.



Relevant Pages

  • Re: Mr Gans in the SF Chron
    ... "My mission," says Gans, "is to put the Grateful Dead's best foot ... forward every week and explore the roots and branches of that tree, ... branches of that tree" here in this group. ... Rock on, Mr. Gans! ...
    (rec.music.gdead)
  • Re: Roots of x^3 = 1;
    ... >> I was teaching myself some algebra when I got stuck at the following ... If you need to review polar form, ... I managed to figure out deal on these roots on my own (After some ...
    (sci.math)
  • Re: irreducible factors of x^n-1
    ... You have no idea how grateful I am. ... I do need to clarify a few things: ... Why are its other roots also of the type b^p; and so why are the b^p all conjugate to each other? ... Can you elaborate on the sentence: ''if you apply the Frobenius map enough times you can go from any one root to any other root.'' ...
    (sci.math)
  • Re: Help. Where is my error?
    ... quadratic equation has two distinct real roots: ... printf ("\nYour quadratic equation has two same: ... quadratic equation has two distinct imaginary roots. ... constant a,b and c for finding the roots of quadrati ...
    (comp.lang.c)
  • Re: Roots of x^3 = 1;
    ... > I was teaching myself some algebra when I got stuck at the following ... >and infinite complex roots - this must be bogus. ...
    (sci.math)