doesnt make sense

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2003
Posts: 58
Reputation: fakespike is an unknown quantity at this point 
Solved Threads: 0
fakespike fakespike is offline Offline
Junior Poster in Training

doesnt make sense

 
0
  #1
Sep 25th, 2003
well i made this little program to help me check my algebra home work it was soppose to be a simple thing so it is badly coded and rushed but something has happened that i dont understand. i have spotted the problem but dont know why its doing this.
for values a=1 b=-2 c=-3
it works fine i get the right answer
but for values a=1 b=8 c=10 ths anwser should be -1.55 or -6.45.
problem is it does the wrong if statement but why?.
this program is for the algebra equation (-b(+)(-)root(b^2-4ac)) /2

#include <iostream.h>
#include <conio.h>
#include <math.h>
double a;
void equation();
void main()
{
cout<<"*******************************\n"
<<"**** press -1 to exit ****\n"
<<"*******************************\n";

while(a>=0)
equation();
getch();
}
void equation()
{
double b,c,ac,e,z,f,g,j,divider;
cout << "please input a value for a: ";
cin >> a;
if(a!=-1)
{
cout << "please input a value for b: ";
cin >> b;
cout << "please input a value for c: ";
cin >> c;
ac = -4*a*c;

************************
if (ac <= 0) * problem here
e = pow(b,2)-ac; *
else *
e = pow(b,2)+ac; *
************************
divider = 2*a;
z = sqrt(e);

f= (-(b)+z)/divider;
g=(-(b)-z)/divider;
cout << "answer = " << g << " Or " << f;
cout<< "\n";
cout<< "\n";
}
}

plz help
Last edited by fakespike; Sep 25th, 2003 at 9:40 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC