Help. Where is my error?
- From: "Red Dragon" <tskhoon@xxxxxxxxxxxx>
- Date: Mon, 17 Oct 2005 21:58:22 +0800
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 */
12.10.05 */
#include
<stdio.h>
#include <stdlib.h>
#include <math.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;
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 ("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
{
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)?");
scanf ("%c",&q);
printf ("the values of the imaginary roots (Y/N)?");
scanf ("%c",&q);
printf ("\nq =
%c\n",q);/* Test statement*/
if
(p==q)
printf ("OK I will show your the imaginary roots tomorrow.\n");
printf ("OK I will show your the imaginary roots tomorrow.\n");
else
printf ("Good bye\n");
printf ("Good bye\n");
return
0;
}
}
}
- Follow-Ups:
- Re: Help. Where is my error?
- From: Old Wolf
- Re: Help. Where is my error?
- From: Keith Thompson
- Re: Help. Where is my error?
- From: Michael Mair
- Re: Help. Where is my error?
- From: Walter Roberson
- Re: Help. Where is my error?
- From: Geoff Turner
- Re: Help. Where is my error?
- Prev by Date: Re: Determine calling function
- Next by Date: Re: Help. Where is my error?
- Previous by thread: http://cprogrammers.blogspot.com/
- Next by thread: Re: Help. Where is my error?
- Index(es):
Relevant Pages
|