| | |
doesnt make sense
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2003
Posts: 58
Reputation:
Solved Threads: 0
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
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
- Word Association Game (Posting Games)
- Regular expression doesn't make sense (Perl)
- seg fault that doesnt make sense (C++)
- Whats Wrong Withj This 6800 Graphic Card (Monitors, Displays and Video Cards)
- System security software on XP (Viruses, Spyware and other Nasties)
- XPpro to WinME networking from hell :( (Networking Hardware Configuration)
- 100% CPU Usage - No Virus, No gaming (Windows NT / 2000 / XP)
- Happy Thanksgiving! (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: How to exit without exit?
- Next Thread: help about programming
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





