944,006 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2608
  • C++ RSS
Sep 25th, 2003
0

doesnt make sense

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
fakespike is offline Offline
58 posts
since Jul 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to exit without exit?
Next Thread in C++ Forum Timeline: help about programming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC