HELP HELP

This is a big one and I don't understand

Write a C++ function named quadratic which has parameters a,b, and c of type int which calculates only double?
Write a C++ function named quadratic which has parameters a,b, and c of type int which calculates only double real roots of quadratic equations according to the formula:

r1=-b+Sqrt(b^2-4ac)/(2a)), r2=-b- Sqrt(b^2-4ac)/(2a))

The two real roots are passed back to the caller via two parameters r1 and r2 of type float. When quadratic cannot calculate two real roots, it prints out the appropriate error message and returns -1 to the caller as a warning not to use the values of the roots. When it can calculate two real solutions, it returns 1 to the caller to indicate success.
You can start by writing the signature of the function, then we can look at filling it in.
closed account (18hRX9L8)
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
/* quad.c
 * ----------
 * Quadratic Equation Problem Phase #4. Created by Usandfriends.
 */
 
#include <stdio.h>                                                              //include
#include "genlib.h"
#include "simpio.h"
#include "math.h"

main()
{
      float answer1,answer2,a,b,c,bsq,fac,ta,nob,lin;                               //assign variables
      
      printf ("Quadratic Equation Problem Phase #4.\n");                        //Get Numbers
      printf ("Enter \"a\" value.  ");
      a=GetInteger();
      printf ("Enter \"b\" value.  ");
      b=GetInteger();
      printf ("Enter \"c\" value.  ");
      c=GetInteger();

      bsq=b*b;                                                                  //initialization
      fac=4*a*c;
      ta=2*a;
      nob=-1*b;
      lin=-1*(c/b);
      
      if (bsq<fac)                                                    //check for imaginaries
          printf ("Imaginary Solution(s)");
      else if (a==0) {
          if (b==0){
             if (c==0){
                  printf ("All Real Numbers.");}
             else {
             printf ("Undifined Solution(s)");  }}
          else {                                                    //check for undefined solutions
          printf ("The linear solution is: %.2f.\n",lin);}}
      else if (bsq==fac)                                                        //check for one solution
      {
          answer1=(nob-(sqrt(bsq-fac)))/ta;
          printf ("Only one solution: %.2f\n",answer1);
      } 
      else                                                                      //otherwise continue!
      {
          answer1=(nob-(sqrt(bsq-fac)))/ta;
          answer2=(nob+(sqrt(bsq-fac)))/ta;
          printf ("1st Solution = %.3f\n",answer1);
          printf ("2nd Solution = %.3f\n",answer2);
      }
      
getchar();                                                                      //safely exit
}

                                                                                //party! 
That's not a function, that's an entire program. But, it doesn't declare a return type for main or have a return statement. And it's written in C on a C++ board. :p
Do you understand what a function is? And if you know that, do you understand how to code one in C or C++?
Topic archived. No new replies allowed.