Re: Help. Where is my error?
- From: "Geoff Turner" <g.s.turner@xxxxxxxx>
- Date: Mon, 17 Oct 2005 15:26:44 +0100
"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>
.
- Follow-Ups:
- Re: Help. Where is my error?
- From: Walter Roberson
- Re: Help. Where is my error?
- References:
- Help. Where is my error?
- From: Red Dragon
- Help. Where is my error?
- Prev by Date: Help. Where is my error?
- Next by Date: Re: weird but interesting code - needs help
- Previous by thread: Help. Where is my error?
- Next by thread: Re: Help. Where is my error?
- Index(es):
Relevant Pages
|