Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey im writing a program in c++ its for a quadratic calculator. The program has

ID: 640811 • Letter: H

Question

Hey im writing a program in c++ its for a quadratic calculator. The program has a main and a seperate file i used to write the functions. Currently i am using global variables. On my main file i have

#include
#include

using namespace std;

double root1, root2;
bool rootCalc(double a, double b, double c, double& root1, double& root2, bool& roots, double& discrim);

int main(){

    //double discrim;
    //double a, b, c;
    //bool roots;
    //a = getValue();
    //b = getValue();
    //c = getValue();

    rootCalc(a, b, c, root1, root2, roots, discrim);

}

(i dont believe whats commented applys right now)

on my function file i wrote

bool rootCalc(double a, double b, double c, double& root1, double& root2, bool& roots, double& discrim) {
   discr(a, b, c, discrim);
   if (discrim >= 0) {                 //discr >= 0 solves the special case when b^2 - 4ac = 0 (like a = 1, b = -4, c = 4)
       if (a != 0)                   //quadratic equation
       {
           root1 = (-b + sqrt(discrim)) / (2 * a);
           root2 = (-b - sqrt(discrim)) / (2 * a);

       }
       else                        //linear equation
           root1 = -c / b;           //then set only one roor that to -c/b
       return roots = true;
   }
   else {
       return roots = false;

   }
}

Theres several more functions i wrote for the program but for my question im just curious how to change my rootCalc() function so that it pass the calculated roots back to the caller by reference parameters (NO USE OF GLOBAL VARIABLES). Thanks for the help!!

Explanation / Answer

#include #include #include #include using namespace std; int main() { double a,b,c,x1,x2; char x; couta; coutb; coutc; cout