Quadratic Equation pointer problem

So, I successfully made a program that will perform the quadratic equation on three numbers, imaginary or real. however, i am now trying to simplify the result, as to get rid of the "/2a" on the bottom. Hence the simplify() function. I just started to create thes implification function, and am attempting to divide tehe imaginary parrt of the solution as well as the real part of the solution by 2a. Somehow, it gives the error, "error:invalid operands of types 'int' and 'double *' to binary 'operator*'" on lines 105 and 106. I suspect it has to do with the pointers and references that i am passing as parameters. Im new to that idea. Also, just an aside, I have never actualyl seeen "/=" be used. It can be, right? I know "+=" can be.

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//july fourth, 2014
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>//simplify the answer
using namespace std;

int count=0;
//prototyping
double ans_1(double,double,double);
double ans_2(double,double,double);
double nanhe(double,double,double);
void simplify(double*,double*,double*);

int main()
{

double a,b, c;
cout<<"Quadratic Equation Solver \n";
cout<<"Enter a value for a: ";
cin>>a;
cout<<endl;
cout<<"Enter a value for b: ";
cin>>b;
cout<<endl;
cout<<"Enter a value for c: ";
cin>>c;
cout<<endl;

if ( isnan(sqrt((b*b)-(4*a*c))))
    {
        count++;
    }
    if (!count)
    {
        double answer01=ans_1(a,b,c);
        double answer02=ans_2(a,b,c);
        cout<<"X="<<answer01<<endl;
        cout<<"X="<<answer02<<endl;
    }
    else if (count) //could route these imag ones to separate funcitons instead of count++
    {
    double answer01=ans_1(a,b,c);
    double answer02=ans_1(a,b,c);
        cout<<"X=("<<-b<<"+"<<answer01<<"i)/"<<2*a<<endl;
        cout<<"X=("<<-b<<'-'<<answer02<<"i)/"<<2*a<<endl;
    }
system("pause");
}


double ans_1(double a, double b, double c)
{
double ans1;
double temp_c=sqrt((b*b)-(4*a*c));
    if (isnan(temp_c))
    {
        temp_c=nanhe(a,b,c);
    }
    if (!count)
    {
    ans1=((-b+temp_c)/(2*a));
    }
    else if (count)
    {
    ans1=((temp_c));
    }
    simplify(&a,&b,&ans1);
    return ans1;
}

double ans_2(double a, double b, double c)
{
double ans2;
double temp_d=sqrt((b*b)-(4*a*c));
    if (isnan(temp_d))
    {
        temp_d=nanhe(a,b,c);
    }
    if (!count)
    {
    ans2=((-b-temp_d)/(2*a));
    }
    else if (count)
    {
    ans2=(temp_d);
    }
    simplify(&a,&b,&ans2); //line under this should alter ans2 so its returning the simplified version instead, or just make a new variable instead of ans2
    return ans2;
}


double nanhe(double a, double b, double c) //still need to apply simplify() to nanhe
{
    double temp_help;
temp_help=sqrt(-1*((b*b)-(4*a*c)));
count++;
return temp_help;
}



void simplify(double* a, double* b, double* ans) //only run if complex
{
ans/=(2*a);
b/=(2*a);

}


Last edited on
Topic archived. No new replies allowed.