Pass by Reference and Polynomial Roots

Hello!
I am an extreme beginner to programming and I'm struggling to understand what i'm doing wrong on my current assignment.
My professor wants us to write a C++ program that utilizes a function named “find_root” to find the roots of a second order polynomial. Prompt the user for the coefficients and you must create the “find_root” function and all arguments must be "pass by reference". In this case, “find_root” need only be called once per execution of the program. All output must be from within the main program. Only three arguments can be used in the function and all must be pass by reference. No global variables can be used.
I keep getting the wrong answers and I can't figure out if i'm doing pass by reference incorrectly or if it's my math but here is what I have so far.
Any hints will be greatly appreciated.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>

using namespace std;

void find_root(double&, double&, double&, double&, double&);
int main()

{
	double a = 0;
	double b = 0;
	double c = 0;
	double disc = 0;
	double x1 = 0;
	double x2 = 0;
	string ans = "yes";

	while (ans == "yes")

	{

		cout << "Please enter a value for A " << endl;
		cin >> a;
		cout << "Please enter a value for B " << endl;
		cin >> b;
		cout << "Please enter a value for C " << endl;
		cin >> c;
		system("cls");

		find_root(a, b, c, x1, x2);

		if (disc < 0)
		{

			cout << "The roots are " << fixed << setw(6) <<    setprecision(3) << (-b / (2 * a)) << " +/- "
				<< fixed << setw(6) << setprecision(3) << (sqrt(abs(disc)) / 2 * a) << " i" << endl << endl;

		}
		else

			if (a == 0)
				cout << "Please enter a value other than 0." <<    endl << endl;

			else
			{
				cout << "The roots are " << fixed << setw(6) << setprecision(3) << x1 << " and "
					<< fixed << setw(6) << setprecision(3) << x2 << endl << endl;


			}

		cout << "Would you like to run this program again? Enter Yes or No." << endl << endl;
		cin >> ans;
	}

	system("pause");
	return 0;
}

void find_root(double& a, double& b, double& c, double &x1, double &x2) 
{
	double disc = b*b - 4 * a*c;

	x1 = (-b + sqrt(abs(disc))) / (2 * a);
	x2 = (-b - sqrt(abs(disc))) / (2 * a);
	

	return;
}
Topic archived. No new replies allowed.