Please, please, please make suggestions on how to resolve these errors.
I am trying to build a program that computes a, b, c for the quadratic equation but I'm not having any luck. It's been 5 hours and I've only manage to clear 4 of my errors.
Please note the primary focus is to use function calls. The main function needs to pass the coefficients to a function root1 that computes and returns the value of x1 to the main. I am trying to do the same with x2. The return type should be a floating point.
Any help is greatly appreciated! thx.
****
[code=cpp]
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int main ()
{
int a, b, c, x1, x2;
cout << "Please enter coefficients a, b, and c of the Quadratic Equation, ax^2 + bx + c = 0: " << "\n";
cout << "Please enter a value for coefficient a, where coefficients a and b are not equal to 0: " << "\n";
cin >> a >> b >> c;
}
int Calculate_First _Root (int a, int b, int c, float x1)
{
x1 = (- b + sqrt(pow(b, 2) + 4 * a * c) ) / (2 * a);
cout << "The real root value =" << x1 << "\n";
}
int Calculate_Secon d_Root (int a, int b, int c, float x2)
{
x2 = (- b - sqrt(pow(b, 2) + 4 * a * c) ) / (2 * a);
cout << "The real root value =" << x2 << "\n";
getch();
}[/code]
****Errors:
1>------ Build started: Project: Quad, Configuration: Debug Win32 ------
1>Compiling...
1>Quad.cpp
1>c:\ : warning C4101: 'x2' : unreferenced local variable
1>c:\ : warning C4101: 'x1' : unreferenced local variable
1>c:\ : error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(575): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(527): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(489): or 'double pow(double,int) '
1> while trying to match the argument list '(int, int)'
1>c:\ : error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(575): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(527): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(489): or 'double pow(double,int) '
1> while trying to match the argument list '(int, int)'
1>Quad - 2 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I am trying to build a program that computes a, b, c for the quadratic equation but I'm not having any luck. It's been 5 hours and I've only manage to clear 4 of my errors.
Please note the primary focus is to use function calls. The main function needs to pass the coefficients to a function root1 that computes and returns the value of x1 to the main. I am trying to do the same with x2. The return type should be a floating point.
Any help is greatly appreciated! thx.
****
[code=cpp]
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
int main ()
{
int a, b, c, x1, x2;
cout << "Please enter coefficients a, b, and c of the Quadratic Equation, ax^2 + bx + c = 0: " << "\n";
cout << "Please enter a value for coefficient a, where coefficients a and b are not equal to 0: " << "\n";
cin >> a >> b >> c;
}
int Calculate_First _Root (int a, int b, int c, float x1)
{
x1 = (- b + sqrt(pow(b, 2) + 4 * a * c) ) / (2 * a);
cout << "The real root value =" << x1 << "\n";
}
int Calculate_Secon d_Root (int a, int b, int c, float x2)
{
x2 = (- b - sqrt(pow(b, 2) + 4 * a * c) ) / (2 * a);
cout << "The real root value =" << x2 << "\n";
getch();
}[/code]
****Errors:
1>------ Build started: Project: Quad, Configuration: Debug Win32 ------
1>Compiling...
1>Quad.cpp
1>c:\ : warning C4101: 'x2' : unreferenced local variable
1>c:\ : warning C4101: 'x1' : unreferenced local variable
1>c:\ : error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(575): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(527): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(489): or 'double pow(double,int) '
1> while trying to match the argument list '(int, int)'
1>c:\ : error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(575): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(527): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 9.0\vc\include\ math.h(489): or 'double pow(double,int) '
1> while trying to match the argument list '(int, int)'
1>Quad - 2 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Comment