Floating point error

'domain abnormal program termination is appearing on the user screen I got stuck in this simple program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 #include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c,d,x1,x2;
clrscr();
cout<<"Enter the value of a,b & c of quadratic expression ax2+bx+c\n\n\n\n\n";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
x1=(-b)+sqrt(d)/2*a;
cout<<"x1=\n\n"<<x1;
x2=(-b)-sqrt(d)/2*a;
cout<<"x2="<<x2;
cin>>"";
return 0;
}
Line 15 is an error.
cin >> needs somewhere to store the input. It cannot put it in the empty string "" which is a read-only value.

By the way, /2*a means first divide by 2, then multiply the result by a. For the correct result it should be /(2*a) which means first multiply a by 2, then divide by that number.


Also, check that d is not negative before attempting to get the square root
Last edited on
Thanks a lot
Topic archived. No new replies allowed.