Wierd errors

Hello! I am trying to code a program that can solve quadratic equations. The problem I seem to be having is that when I try to compile it, it comes up with errors leading to the math.h file. This is the code:
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
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;


void clearBuffer()
{
    cin.clear();
    cin.ignore( numeric_limits< streamsize >::max(), '\n' );
}

int a;
int b;
int c;


bool choice= "Nothing.";

int quadratica (int a, int b, int c)
{
    int z;
    z=(-b)+pow(sqrt(b)-(4*a*c));
    return(z);
}

int quadraticb (int a, int b, int c)
{
    int x;
    x=(-b)-pow(sqrt(b)-(4*a*c));
    return(x);
}


int main(){

    cout << "Welcome to the Maths Problem solver, this program has been designed to work out answers for you." << endl;
    cout << "Pick which kind of formulae do you want to use:" << endl;
    cout << "1) ax^2  +  bx  +  c  =  0" << endl;

    cin >> choice;
    
    {
             clearBuffer();
             }
    
    
    if(choice="1"){
    cout << "Input your a:" << endl;
    cin >> a;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cout << "Input your b:" << endl;
    cin >> b;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cout << "input your c:" << endl;
    cin >> c;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    {    
    int x;
    x = quadratica (a,b,c);
    cout << "Your first answer is " << x << endl;
    }
    {
    int y = quadraticb (a,b,c);
    cout << "Your second answer is " << y << endl;
    }
    
    
system("pause");
return 0;
}


and this is the error log(that was found on the math header file):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Compiler: Default compiler
Executing  g++.exe...
g++.exe "E:\c++mathsmonster122PROTOTYPE.cpp" -o "E:\c++mathsmonster122PROTOTYPE.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
C:/Dev-Cpp/include/math.h: In function `int quadratica(int, int, int)':
C:/Dev-Cpp/include/math.h:150: error: too few arguments to function `double pow(double, double)'
E:\c++mathsmonster122PROTOTYPE.cpp:25: error: at this point in file

E:\c++mathsmonster122PROTOTYPE.cpp:25: warning: converting to `int' from `double'
C:/Dev-Cpp/include/math.h: In function `int quadraticb(int, int, int)':
C:/Dev-Cpp/include/math.h:150: error: too few arguments to function `double pow(double, double)'
E:\c++mathsmonster122PROTOTYPE.cpp:32: error: at this point in file
E:\c++mathsmonster122PROTOTYPE.cpp:32: warning: converting to `int' from `double'

Execution terminated


Any help will be greatly appreciated! :)
Last edited on
1
2
3
4
double quadratica (double a, double b, double c)
{
    return -b + sqrt(b*b - 4*a*c);
}
Hello! Thanks for the quick response!
I changed the code to look like this:
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
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;


void clearBuffer()
{
    cin.clear();
    cin.ignore( numeric_limits< streamsize >::max(), '\n' );
}

double a;
double b;
double c;


bool choice;

double quadratica (double a, double b, double c)
{
    return -b + sqrt(b*b - 4*a*c);
}

int quadraticb (double a, double b, double c)
{
    return -b - sqrt(b*b - 4*a*c);
}


int main(){

    cout << "Welcome to the Maths Problem solver, this program has been designed to work out answers for you." << endl;
    cout << "Pick which kind of formulae do you want to use:" << endl;
    cout << "1) ax^2  +  bx  +  c  =  0" << endl;

    cin >> choice;
    
    {
             clearBuffer();
             }
    
    
    if(choice="1"){
    cout << "Input your a:" << endl;
    cin >> a;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cout << "Input your b:" << endl;
    cin >> b;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cout << "input your c:" << endl;
    cin >> c;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
          {
          int x;
          x = quadratica (a,b,c);
          cout << "Your first answer is " << x << endl;
          }
     {
     int y;
     y = quadraticb (a,b,c);
     cout << "Your second answer is " << y << endl;
     }
    
    
system("pause");
return 0;
}


But I still get these errors:
1
2
3
4
5
6
7
8
9
10
11
12
Compiler: Default compiler
Executing  g++.exe...
g++.exe "E:\c++mathsmonster122PROTOTYPE.cpp" -o "E:\c++mathsmonster122PROTOTYPE.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
E:\c++mathsmonster122PROTOTYPE.cpp: In function `int quadraticb(double, double, double)':
E:\c++mathsmonster122PROTOTYPE.cpp:29: warning: converting to `int' from `double'

E:\c++mathsmonster122PROTOTYPE.cpp: In function `int main()':
E:\c++mathsmonster122PROTOTYPE.cpp:58: warning: converting to `int' from `double'

E:\c++mathsmonster122PROTOTYPE.cpp:70: error: expected `}' at end of input

Execution terminated 
Change the return type of function quadraticb() from int to double.


In function main(), there is a missing closing brace } at the end of the if statement.

Change bool choice; to char choice;

Change this:
if (choice="1")
to
if (choice == '1')
note = is the assignment operator
and == is the comparison operator to test "is equal to"
Thank you for the quick responses!
I changed the code around and now it looks like this:
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
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;


void clearBuffer()
{
    cin.clear();
    cin.ignore( numeric_limits< streamsize >::max(), '\n' );
}

double a;
double b;
double c;


char choice;

double quadratica (double a, double b, double c)
{
    return -b + sqrt(b*b - 4*a*c);
}

double quadraticb (double a, double b, double c)
{
    return -b - sqrt(b*b - 4*a*c);
}


int main(){

    cout << "Welcome to the Maths Problem solver, this program has been designed to work out answers for you." << endl;
    cout << "Pick which kind of formulae do you want to use:" << endl;
    cout << "1) ax^2  +  bx  +  c  =  0" << endl;

    cin >> choice;
    
    {
             clearBuffer();
             }
    
    
    if(choice == "ax^2  +  bx  +  c  =  0"){
    cout << "Input your a:" << endl;
    cin >> a;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cout << "Input your b:" << endl;
    cin >> b;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cout << "input your c:" << endl;
    cin >> c;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
          {
          int x;
          x = quadratica (a,b,c);
          cout << "Your first answer is " << x << endl;
          }
     {
     int y;
     y = quadraticb (a,b,c);
     cout << "Your second answer is " << y << endl;
     }
}
    
system("pause");
return 0;
}


which still seems to return this error log:
1
2
3
4
5
6
7
8
9
10
11
12
Compiler: Default compiler
Executing  g++.exe...
g++.exe "E:\c++mathsmonster122PROTOTYPE.cpp" -o "E:\c++mathsmonster122PROTOTYPE.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
E:\c++mathsmonster122PROTOTYPE.cpp: In function `int main()':
E:\c++mathsmonster122PROTOTYPE.cpp:46: error: ISO C++ forbids comparison between pointer and integer

E:\c++mathsmonster122PROTOTYPE.cpp:58: warning: converting to `int' from `double'

E:\c++mathsmonster122PROTOTYPE.cpp:63: warning: converting to `int' from `double'

Execution terminated
 


any ideas? Thanks
Last edited on
I changed the code a little bit 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
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
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;


void clearBuffer()
{
    cin.clear();
    cin.ignore( numeric_limits< streamsize >::max(), '\n' );
}

double a;
double b;
double c;


char choice;

double quadratica (double a, double b, double c)
{
    return -b + sqrt(b*b - 4*a*c);
}

double quadraticb (double a, double b, double c)
{
    return -b - sqrt(b*b - 4*a*c);
}


int main(){

    cout << "Welcome to the Maths Problem solver, this program has been designed to work out answers for you." << endl;
    cout << "Pick which kind of formulae do you want to use:" << endl;
    cout << "1) ax^2  +  bx  +  c  =  0" << endl;

    cin >> choice;
    
    {
             clearBuffer();
             }
    
    
    if(choice == "ax^2  +  bx  +  c  =  0"){
    cout << "Input your a:" << endl;
    cin >> a;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cout << "Input your b:" << endl;
    cin >> b;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cout << "input your c:" << endl;
    cin >> c;
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
          {
          double x;
          x = quadratica (a,b,c);
          cout << "Your first answer is " << x << endl;
          }
     {
     double y;
     y = quadraticb (a,b,c);
     cout << "Your second answer is " << y << endl;
     }
}
    
system("pause");
return 0;
}


which still returns this error log:
1
2
3
4
5
6
7
Compiler: Default compiler
Executing  g++.exe...
g++.exe "E:\c++mathsmonster122PROTOTYPE.cpp" -o "E:\c++mathsmonster122PROTOTYPE.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
E:\c++mathsmonster122PROTOTYPE.cpp: In function `int main()':
E:\c++mathsmonster122PROTOTYPE.cpp:46: error: ISO C++ forbids comparison between pointer and integer

Execution terminated 


Any ideas? Thanks
choice is a char. You are trying to compare it with a string of 23 characters.
From the compiler's perspective, you are trying to compare a char with a pointer to a string, which is not valid.

I can only repeat my previous recommendation:
if (choice == '1')
I don't understand, it doesn't matter whether I switch choice to "1", whether I change the type of 'choice', it always keeps up coming with the same error. :(
Use single quotes! (:
What's the point of if( choice == ... )? You should be using string choice instead if char choice (on line 20) if you want to compare to a string, and 'single quotes' (not "double quotes") if you want to compare to a charecter. But why bother with the comparison at all?
Last edited on
I fixed this problem by converting choice back to bool!
@Lynx876
Thank you for helping me again! :D I didn't notice that :S Kept using double until I realized what did you and Chervil mean! Thanks :D

@Mathead200
because I want to add more functions in the future, this was just the first one that I wanted to add.
Glad you got some sort of solution.
Bool of course will only allow two choices, true and false, so it's not a permanent solution.
Topic archived. No new replies allowed.