| | |
Quadratic Formula
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread 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
C Syntax (Toggle Plain Text)
#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"); }
_________________________
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
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 3: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.
C Syntax (Toggle Plain Text)
#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: 3,836
Reputation:
Solved Threads: 503
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:
C Syntax (Toggle Plain Text)
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 1:01 am.
•
•
Join Date: Jan 2008
Posts: 3,836
Reputation:
Solved Threads: 503
•
•
•
•
You're getting C++ errors. C++ is a lot stricter. Try using a C compiler.
You have that backwards. These lines:
C Syntax (Toggle Plain Text)
#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 11:25 am.
New members chased away this month: 3
•
•
Join Date: Jan 2008
Posts: 3,836
Reputation:
Solved Threads: 503
•
•
•
•
"cannot convert from" is a C++ (and in general, OOP) only error afaik.
Ah, OK, you are referring to these lines, perhaps?
C Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- The Vending Machine Game (Posting Games)
- Help explain how to write algorithm (Computer Science)
- 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?)
| Thread Tools | Search this Thread |
Tag cloud for C
#include ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware histogram homework inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming spoonfeeding standard string strings structures student systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






