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<<"let's solve a quadratic equation.\n\n";
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