| | |
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
Views: 2419 | Replies: 0
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory newbie news number output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





