# Thread: Hello Forum/ Simple Program help

1. ## Hello Forum/ Simple Program help

Hello forum friends

I just started learning C++ on my own and naturally its a bit tricky but the challlenge is kind of the point right. anyways I wrote "hello world" and than a simple program to multiply two numbers and then I decided to apply it to the quadratic equation and now I am stuck.

Right now the compiler gets to the
Code:
`return ((-b)-(sqrt(pow(b,2)-4*a*c)))/(2*a)`
line before telling me that b is undefined in this function.

Here is my program so far:
Code:
```#include <iostream>
using namespace std;
int x1();
int x2();
int sqrt;
int main()
{
float a, b, c;
cout<<"What is the coefficient of the first term? ";
cin>>a;
cin.ignore();
cout<<"What is the coefficient of the second term? ";
cin>>b;
cin.ignore();
cout<<"What is the constant? ";
cin>>c;
cin.ignore();
cout<<"X=";
int x1;
}
int x1
{
return ((-b)-(sqrt(pow(b,2)-4*a*c)))/(2*a)
}
int x2
{
return ((-b)+(sqrt(pow(b,2)-4*a*c)))/(2*a)
}```
I think the problem is mostly that I don't know how to properly format the equation itself in the variable to be returned ( hope that makes sense). It also looks like I will run into some problems with the cin.get/cin.ignore stuff too but the main thing I am struggling with is just getting that equation to spit out the answer.

I will keep playing with it but any help would be appriciated

Thank You

2. It looks like you did not define the functions x1 and x2 correctly. You should be declaring some parameters (a, b and c) for these functions, and then passing the local variables a, b, and c as arguments when you call these functions.

Incidentally, it might make more sense to define a function to compute the discriminant, and then pass the discriminant to x1 and x2, perhaps after checking whether the discriminant is negative.

Oh, and remember to indent your code reasonably and consistently.

3. the problem involved not including <math.h> mostly (which I now know exists) and also that I was doing things with the x1 and x2 that didn't make sense and I while I still dont know why I have fixed it

Code:
```#include <iostream>
#include <math.h>
using namespace std;
int x1();
int x2();
int main()
{
float a, b, c;
cout<<"What is the coefficient of the first term? ";
cin>>a;
cin.ignore();
cout<<"What is the coefficient of the second term? ";
cin>>b;
cin.ignore();
cout<<"What is the constant? ";
cin>>c;
cin.ignore();
cout<< ((-b)-(sqrt(pow(b,2)-4*a*c)))/(2*a)<<","<<((-b)-(sqrt(pow(b,2)-4*a*c)))/(2*a);
cin.get();
}```
will now run the quadratic equation properly

but thanks for the tip about the discriminant laserlight thats a good idea and I am gonna start on that next.

4. Originally Posted by beyondhuman
the problem involved not including <math.h> mostly (which I now know exists)
C++ borrowed/stole <math.h> from C and calls it <cmath> with some additions and changes to the functions provided. As such, I suggest that you #include <cmath> instead.

Originally Posted by beyondhuman
I was doing things with the x1 and x2 that didn't make sense and I while I still dont know why I have fixed it
It looks like you "fixed it" by not defining those functions, so essentially you declared the functions x1 and x2 but never did anything else with them.