•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,787 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,794 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 552 | Replies: 15 | Solved
![]() |
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
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");
} _________________________
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
•
•
Join Date: Dec 2006
Posts: 210
Reputation:
Rep Power: 2
Solved Threads: 15
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 ????
And the in the if statment, there two two equals opeator not the assignment operator
ssharish
C Syntax (Toggle Plain Text)
#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
Last edited by ssharish2005 : Jul 24th, 2008 at 2:50 pm.
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;
} _________________________
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
•
•
Join Date: Jan 2008
Posts: 1,499
Reputation:
Rep Power: 6
Solved Threads: 189
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:
^ is the bitwise XOR operator and I think (1 / 2) is going to be 0 due to integer division.
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.
Last edited by VernonDozier : Jul 25th, 2008 at 12:01 am.
•
•
Join Date: Jan 2008
Posts: 1,499
Reputation:
Rep Power: 6
Solved Threads: 189
•
•
•
•
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.
>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.
>"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++.
So your advice is to ignore the warning and let the problem silently continue. Brilliant.
>"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++.
Last edited by Narue : Jul 25th, 2008 at 10:25 am.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: Jan 2008
Posts: 1,499
Reputation:
Rep Power: 6
Solved Threads: 189
•
•
•
•
"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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- The Vending Machine Game (Posting Games)
- Help explain how to write algorithm (Computer Science and Software Design)
- Quadratic probing insert function help (C++)
- some simple problems... (C++)
- What now? (VB.NET)
- cmath coding (C++)
- Can anyone help me with my c language homework please? (C)
- representing a quadratic equation (C)
- Desperate help needed (C++)
Other Threads in the C Forum
- Previous Thread: help needed to compute maclaurin series using c
- Next Thread: error C2447: '{' : missing function header (old-style formal list?)



Linear Mode