User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 427,225 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,221 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: 650 | Replies: 15 | Solved
Reply
Join Date: Jul 2008
Posts: 37
Reputation: plike922 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
plike922's Avatar
plike922 plike922 is offline Offline
Light Poster

Quadratic Formula

  #1  
Jul 24th, 2008
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");
}
_________________________
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 232
Reputation: joshmo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: Quadratic Formula

  #2  
Jul 24th, 2008
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
Reply With Quote  
Join Date: Dec 2006
Posts: 232
Reputation: ssharish2005 is on a distinguished road 
Rep Power: 2
Solved Threads: 18
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Quadratic Formula

  #3  
Jul 24th, 2008
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 ????

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int a, b, c, x, y, z;
  6.  
  7. printf("Enter A: ");
  8. a = GetInteger();
  9.  
  10. printf("Enter B: ");
  11. b = GetInteger();
  12.  
  13. printf("Enter c: ");
  14. c = GetInteger();
  15.  
  16. z = ( b * b - 4 * a * c );
  17. x = ( ( -b - z ) / ( 2 * a ) );
  18. y = ( ( -b + z ) / ( 2 * a ) );
  19.  
  20. if ( x == y )
  21. printf("There is one solution: %d", x);
  22. else if ( x != y )
  23. printf("There are two solutions: %d and %d", x, y);
  24. else
  25. printf("There are no solutions");
  26.  
  27. system("pause");
  28. return 0;
  29. }

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.
Reply With Quote  
Join Date: Jul 2008
Posts: 37
Reputation: plike922 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
plike922's Avatar
plike922 plike922 is offline Offline
Light Poster

Re: Quadratic Formula

  #4  
Jul 24th, 2008
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;
}
_________________________
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
Reply With Quote  
Join Date: Jan 2008
Posts: 1,776
Reputation: VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice 
Rep Power: 8
Solved Threads: 219
VernonDozier VernonDozier is offline Offline
Posting Virtuoso

Re: Quadratic Formula

  #5  
Jul 24th, 2008
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.
Last edited by VernonDozier : Jul 25th, 2008 at 12:01 am.
Reply With Quote  
Join Date: May 2008
Posts: 160
Reputation: Clockowl is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
Clockowl Clockowl is offline Offline
Junior Poster

Re: Quadratic Formula

  #6  
Jul 25th, 2008
You're getting C++ errors. C++ is a lot stricter. Try using a C compiler.
Reply With Quote  
Join Date: Jan 2008
Posts: 1,776
Reputation: VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice 
Rep Power: 8
Solved Threads: 219
VernonDozier VernonDozier is offline Offline
Posting Virtuoso

Re: Quadratic Formula

  #7  
Jul 25th, 2008
Originally Posted by Clockowl View Post
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.
Reply With Quote  
Join Date: May 2008
Posts: 160
Reputation: Clockowl is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
Clockowl Clockowl is offline Offline
Junior Poster

Re: Quadratic Formula

  #8  
Jul 25th, 2008
"cannot convert from" is a C++ (and in general, OOP) only error afaik.
Last edited by Clockowl : Jul 25th, 2008 at 10:16 am.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,333
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Quadratic Formula

  #9  
Jul 25th, 2008
>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++.
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.
Reply With Quote  
Join Date: Jan 2008
Posts: 1,776
Reputation: VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice 
Rep Power: 8
Solved Threads: 219
VernonDozier VernonDozier is offline Offline
Posting Virtuoso

Re: Quadratic Formula

  #10  
Jul 25th, 2008
Originally Posted by Clockowl View Post
"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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 11:33 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC