I am trying to create a program that gets the solution of a quadratic formula, but i keep getting an error and i cant figure it out.

1>quad.cpp(14) : error C2440: '=' : cannot convert from 'int (__cdecl *)(void)' to 'int'
1> There is no context in which this conversion is possible
1>quad.cpp(16) : error C2440: '=' : cannot convert from 'int (__cdecl *)(void)' to 'int'
1> There is no context in which this conversion is possible
1>quad.cpp(18) : error C2440: '=' : cannot convert from 'int (__cdecl *)(void)' to 'int'
1> There is no context in which this conversion is possible
1>quad - 3 error(s), 21 warning(s)

Here is the program

#include <iostream>
#include <stdio.h>
#include "simpio.h"
#include "strlib.h"
#include "random.h"
#include "math.h"
using namespace std;

int main()
{
	int a, b, c, x, y, z;

	printf("Enter A: ");
	a = GetInteger;
	printf("Enter B: ");
	b = GetInteger;
	printf("Enter c: ");
	c = GetInteger;
z = (b*b-4*a*c)
x = ((-b - z)/(2*a));
y = ((-b + z)/(2*a));

if (x = y)
{
	printf("There is one solution: %d", x);
}
else if (x != y)
{
	printf("There are two solutions: %d and %d", x, y);
}
else
{
	printf("There are no solutions");
}
system("pause");
}

There could be a possibility that if "GetInteger" is a function it is not of integer type. Otherwise if "GetInteger" is not a function then it is not declared :)

pLike, you should really consider looking at on how to indentent you code first. Well the error message you get there is basiclly specifying that GetInteger cannot be assigned to the interger. It donst know what the RHS is? Seems to me like it is function or is it macro if there was no brackets ????

#include <stdio.h>

int main()
{
    int a, b, c, x, y, z;

    printf("Enter A: ");
    a = GetInteger();

    printf("Enter B: ");
    b = GetInteger();

    printf("Enter c: ");
    c = GetInteger();

    z = ( b * b - 4 * a * c );
    x = ( ( -b - z ) / ( 2 * a ) );
    y = ( ( -b + z ) / ( 2 * a ) );

    if ( x == y )
    	printf("There is one solution: %d", x);
    else if ( x != y )
    	printf("There are two solutions: %d and %d", x, y);
    else
    	printf("There are no solutions");

    system("pause");
    return 0;
}

And the in the if statment, there two two equals opeator not the assignment operator if ( x == y ) ssharish

Ok... Thanks that solved that, but i have a new problem, i can't get the decimals with the number here is the improved program.

#include <iostream>
#include <stdio.h>
#include "simpio.h"
#include "strlib.h"
#include "random.h"
#include "math.h"
using namespace std;

int main()
{
	int a, b, c, x, y, d;

	printf("Enter A: ");
	a = GetInteger();

	printf("Enter B: ");
	b = GetInteger();

	printf("Enter C: ");
	c = GetInteger();

	d = (b*b-4*a*c)^(1/2);
	x = ((-b - d)/(2.0*a));
	y = ((-b + d)/(2.0*a));

	if (x == y)
		printf("There is one solution: %d\n", x);
	else if (x != y)
		printf("There are two solutions: %d and %d\n", x, y);
	else if (d <= 0)
		printf("There are no solutions.\n");
	else
		printf("There are no solutions.\n");

	system("pause");
	return 0;
}

iostream isn't in C. I think you have quotes where you want <> in your #include for math.h, and you can't use "using namespace std" in C. Maybe you're not using a C compiler.

The problem with the decimals is that you've declared all of your variables as integers and integers can't hold decimals. Try declaring x, y, d as doubles or floats.

I'm also suspicious of this line:

d = (b*b-4*a*c)^(1/2);

^ is the bitwise XOR operator and I think (1 / 2) is going to be 0 due to integer division.

You're getting C++ errors. C++ is a lot stricter. Try using a C compiler. ;)

You're getting C++ errors. C++ is a lot stricter. Try using a C compiler. ;)

You have that backwards. These lines:

#include <iostream>
using namespace std;

are fine with a C++ compiler, but cannot be used with a C compiler.

"cannot convert from" is a C++ (and in general, OOP) only error afaik.

>You're getting C++ errors. C++ is a lot stricter. Try using a C compiler.
So your advice is to ignore the warning and let the problem silently continue. Brilliant. :icon_rolleyes:

>"cannot convert from" is a C++ (and in general, OOP) only error afaik.
You get it in C as well if you do something stupid...just like C++.

"cannot convert from" is a C++ (and in general, OOP) only error afaik.

Ah, OK, you are referring to these lines, perhaps?

x = ((-b - d)/(2.0*a));
y = ((-b + d)/(2.0*a));

I get a warning in C++ (not an error) which says "Warning: Converting from 'int' to 'double'". I don't get the "cannot convert from" error. It converts it using the C++ compiler, but throws out the warning and it's the programmer's decision about whether to pay attention to the warning or not. Maybe it's an error instead of a warning if you have certain compiler flags. In this case, it's a warning that the OP should definitely pay attention to and not ignore. You're right, though, given that this is the C forum and hence the OP should be using a C compiler, there will be no warning whatsoever on these conversions, or at least there wasn't on my C compiler.

iostream isn't in C. I think you have quotes where you want <> in your #include for math.h, and you can't use "using namespace std" in C. Maybe you're not using a C compiler.

The problem with the decimals is that you've declared all of your variables as integers and integers can't hold decimals. Try declaring x, y, d as doubles or floats.

I'm also suspicious of this line:

d = (b*b-4*a*c)^(1/2);

^ is the bitwise XOR operator and I think (1 / 2) is going to be 0 due to integer division.

How do you do that?... Sorry i am kind of new this is my 3rd week in the course i am taking.

I just meant to say he's trying to create a C program I guess, using a C++ compiler since only a C++ compiler will throw that error. Nothing more.

i am still confused here is my program so far do you see any changes?

#include <iostream>
#include <stdio.h>
#include "simpio.h"
#include "strlib.h"
#include "random.h"
#include "math.h"
using namespace std;

int main(double d, double, x, double, y)
{
	int a, b, c, x, y, d;

	printf("Enter A: ");
	a = GetInteger();

	printf("Enter B: ");
	b = GetInteger();

	printf("Enter C: ");
	c = GetInteger();

	d = (b*b-4*a*c)^(1/2);
	x = ((-b - d)/(2.0*a));
	y = ((-b + d)/(2.0*a));
	

	if (x == y)
		printf("There is one solution: %f\n", x);
	else if (x != y)
		printf("There are two solutions: %f and %f\n", x, y);
	else if (d <= 0)
		printf("There are no solutions.\n");
	else
		printf("There are no solutions.\n");

	system("pause");
	return 0;
}

i am still confused here is my program so far do you see any changes?

#include <iostream>
#include <stdio.h>
#include "simpio.h"
#include "strlib.h"
#include "random.h"
#include "math.h"
using namespace std;

int main(double d, double, x, double, y)
{
	int a, b, c, x, y, d;

	printf("Enter A: ");
	a = GetInteger();

	printf("Enter B: ");
	b = GetInteger();

	printf("Enter C: ");
	c = GetInteger();

	d = (b*b-4*a*c)^(1/2);
	x = ((-b - d)/(2.0*a));
	y = ((-b + d)/(2.0*a));
	

	if (x == y)
		printf("There is one solution: %f\n", x);
	else if (x != y)
		printf("There are two solutions: %f and %f\n", x, y);
	else if (d <= 0)
		printf("There are no solutions.\n");
	else
		printf("There are no solutions.\n");

	system("pause");
	return 0;
}

First, make sure you are using a C compiler if this is a C program and make sure the extension at the end of the file is .c, not .cpp. If this is a C++ program, you're in the wrong forum. Assuming it is a C program and you are using a C compiler, this shouldn't compile due to these lines:

#include <iostream>
using namespace std;

You can't use those in C and your program doesn't need them anyway, so you can delete them. Also, you need to replace

#include "math.h"

with

#include <math.h>

I don't know what these files are, but I imagine GetInteger is in one of them.

#include "simpio.h"
#include "strlib.h"
#include "random.h"

Keep your main function as:

int main ()

not

int main(double d, double, x, double, y)

Declare d, x, and y as doubles inside the program, where you are already declaring them as integers.

int a, b, c;
double x, y, d;

^ is not the exponential operator. Use pow or sqrt from math.h instead:

http://www.cplusplus.com/reference/clibrary/cmath/pow.html
http://www.cplusplus.com/reference/clibrary/cmath/sqrt.html

Keep in mind that 1 / 2 = 0 by integer division.
1.0 / 2.0 = 0.5, on the other hand, which is what you would want if you use the pow function.

commented: It helped alot! +1

Thanks for all the help... i am still learning and so glad i have other people than a program to help!

The only thing that don't make me feel good having read this thread is the sign of plike:

COBOL was designed so that managers could read code.
BASIC was designed for people who are not programmers.
FORTRAN is for scientists.
PILOT is for teachers.
C, however, is for programmers.

Because the ^ operator is used in Basic...

;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.