#include <cmath>
#include <iostream>
double QuadRoot (double a, double b, double c);
double a, b, c, D, D2, D3;
int main () {
cout << "Randall Hall \t CSCE 1020 Lab Assignment #10 \t randallhall2@my.unt.edu" << endl;
cout << "\n\n";
do {
cout << "Please enter a number between -100.0 and 100.0 for x^2: ";
cin >> a;
} while (a < -100.0 || a > 100.0);
cout << "a has the value: " << a << ".";
cout << endl;
do {
cout << "Please enter a number between -100.0 and 100.0 for x: ";
cin >> b;
} while (b < -100.0 || b > 100.0);
cout << "b has the value: " << b << ".";
cout << endl;
do {
cout << "Please enter a number between -100.0 and 100.0 for the constant: ";
cin >> c;
} while (c < -100.0 || c > 100.0);
cout << "c has the value: " << c << ".";
cout << "\n\n";
D = (b*b)-(4*a*c);
D2 = (-b+sqrt(D))/(2*a);
D3 = (-b-sqrt(D))/(2*a);
if (D < 0) {
cout << "The determinant is less than 0 so the roots are imaginary/not real" << endl;
};
if (D == 0) {
cout << "The determinant is 0 so there will only be one root, the root is " << D2 << endl << endl;
};
if (D > 0) {
cout << "The determinant is greater than 0 so there will be two roots, the roots are " << D2 << " and " << D3 << endl << endl;
};
return 0;
}
, and it doesn't feel like I have a function defined
That may have been my fault. When I wrote returnType, I meant the type of value returned, not the literal word.
1 2 3 4
int main() //returns an int value
double QuadRoot //returns a double value
string StringFunction //returns a string value
etc...
and the actual return statement must be inside the function body
1 2 3 4 5 6 7
double QuadRoot ( double a, double b, double c)
{
double D;
D= -b + sqrt((b*b) - (4*a*c))/(2*a);
return D; //the variable D is of type double and
//it matches the return type of the function
}
Use a void function and use the address of operator '&' to change D, D2, and D3 then continue with your code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void quad(int &, int &, int &);
int main()
{
//instructions
quad(D, D2, D3);
ifelseif //I'm not going to bother wasting time writing this again for you
else
}
void quad(int &x, int &y, int &z) //actual variable names are unimportant
{
}