Help with pass by reference quadratic program

I need help finishing my program that uses pass by reference and will output all the roots of a quadratic after the user inputs the coefficients (a, b, c). I know there are probably a few errors, but i am stuck and don't know what to do from here. anyone?



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
  #include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

double quad(double&,double&,double&);

int main()
{
	double a;
	double b;
	double c;
	double x1;
	double x2;
	char choice = 'y';






	cout <<"This program will find the roots of a quadratic"<<endl<<endl;

	do{

	cout <<"Please input the values for the coefficients; a, b, c""(y=ax^2+bx+c)"<<endl<<endl;
cin>>a>>b>>c;

if((b * b - 4 * a * c) > 0)
quad(a,b,c);
cout <<"The positive roots are "<<x1<<endl<<endl;

if else ((b * b - 4 * a * c) = 0);
quad(a,b,c);

if else ((b * b - 4 * a * c) < 0);
quad (a,b,c);
cout <<"The negative roots are "<<x2<<endl<<endl;


system ("cls");

cout <<"Would you like to run this again? y or Y for yes, anything else for no"<<endl<<endl;
	
	}while (choice =='y' || choice =='Y');

	system ("Pause");
	return 0;

}


double quad(double&a, double&b, double&c)
{
	x1 = (-b+sqrt(b*b-4*a*c))/(2*a);
	x2 = (-b-sqrt(b*b-4*a*c))/(2*a);



	return;

}
Last edited on
sorry, but can anyone help me plz?
If you want help, you'd better compose yourself and tell exactly at which issue you stuck. "I have written something... and I do not know what write further..." always look at least strange and people really could not understand what to do to help you.
"I know there are probably a few errors, . . ."

You think there are a few errors?! It sounds like you are not sure.

Have you compiled and run this program?

Let's deal with one error at a time. What are the specific errors?
I fixed some of them, but i need help putting my imaginary roots into the form of A+Bi and A-Bi. This is what i have so far:

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 <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

void quad(double&,double&,double&,double&,double&);

int main()
{
	double a;
	double b;
	double c;
	double x1;
	double x2;
	char choice = 'y';






	cout <<"This program will find the roots of a quadratic"<<endl<<endl;

	do{

	cout <<"Please input the values for the coefficients; a, b, c"" (y=ax^2+bx+c)"<<endl<<endl;
cin>>a>>b>>c;

if (a==0)
{ cout <<"If a is 0, then it is a line. Can't divide by 0"<<endl<<endl;
}
else
{
quad(a,b,c,x1,x2);
if((b * b - (4 * a * c)) < 0)
{
cout<<"the imaginary root(s): "<<setw(5)<<fixed<<setprecision(3)<<x1<<"\t"<<x2<<endl<<endl;

}
else  
{
cout<<"the real root(s): "<<setw(5)<<fixed<<setprecision(3)<<x1<<"\t"<<x2<<endl<<endl;

}

}


cout <<"Would you like to run this again? y or Y for yes, anything else for no"<<endl<<endl;
cin >>choice;	

	}while (choice =='y' || choice =='Y');

	system ("Pause");
	return 0;

}


void quad(double&a, double&b, double&c, double&x1, double&x2)
{
	

	x1 = (-b+sqrt((b*b)-4*a*c))/(2*a);
	x2 = (-b-sqrt((b*b)-4*a*c))/(2*a);




}
Topic archived. No new replies allowed.