Program to solve quadratic equation using int function.

So i'm having trouble just setting up this problem... I dont understand how im supposed to use an int function to do this. The exact instructions for the lab are: write a program that asks the user for a,b,c. Implement a function called quad:
int quad(double a, double b, double c, double &r1, double &r2);
-return the number of roots
-r1 should have the first root
-r2 should have the second root

I have such little time... plus another lab so any help would be appreciated...

Heres 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
#include <iostream>
using namespace std;

int quad(double a, double b, double c, double &r1, double &r2);

int main(){
	int num = 0;
	double a, b, c, r1, r2;
	num = quad(a, b, c, r1, r2);

	cout << "Enter A: ";
	cin >> a;
	cout << "Enter B: ";
	cin >> b;
	cout << "Enter C: ";
	cin >> c;
	return a, b, c;

	int quad(double a, double b, double c, double &r1, double &r2){

	}
	if (num == 2){
		cout << r1 << r2;
	}
	system("pause");
}
	

int quad(double a, double b, double c, double &r1, double &r2){
	int det = (b*b - 4 * a*c);
	if (det < 0){
		cout << "There are no roots." << endl;
		return 0;
	}

	return r1, r2;
}

I know... really incomplete and a mess. Please help :[
You're on the right track.
- call quad() after entering the 3 inputs, not before.
- print 0, 1, or 2 roots depending on the return value of quad()
- Inside quad(), set r1 and/or r2 and return the right number.

Here it is sketched out a little more:
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
#include <iostream>
using namespace std;

int quad(double a, double b, double c, double &r1, double &r2);

int 
main()
{
    int num = 0;
    double a, b, c, r1, r2;

    cout << "Enter A: ";
    cin >> a;
    cout << "Enter B: ";
    cin >> b;
    cout << "Enter C: ";
    cin >> c;
    num = quad(a, b, c, r1, r2);

    if (num == 2) {
	cout << r1 << r2;
    } else if (num == 1) {
	// print the one root
    } else {
	// say there are no roots
    }
    system("pause");
}

int 
quad(double a, double b, double c, double &r1, double &r2)
{
    int det = (b * b - 4 * a * c);
    if (det < 0) {
	return 0;
    } /* else if there is one root {
      set r1 to the root
      return 1
    } else there are two roots
       set r1 and r2
       return 2;
    } */
}

awesome thanks alot i finished quite quickly after that!
Topic archived. No new replies allowed.