3 Replies - 421 Views - Last Post: 15 April 2012 - 07:20 AM Rate Topic: -----

#1 Valiantangel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-April 12

Is my code correct?

Posted 15 April 2012 - 07:05 AM

Struggling to solve this.The errors seem to be in x of the polynomial equation.Is my below code ok?


#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	
	double x;
	double polynomial=3x^3-5x^2+6;             /*Errors seem to be pointing here.But this is a given equation*/
	
	x=2.55;
	printf("The value of polynomial is %lf\n",polynomial);

	system("pause");

	return(EXIT_SUCCESS);
}


Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Is my code correct?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2013
  • View blog
  • Posts: 3,038
  • Joined: 21-June 11

Re: Is my code correct?

Posted 15 April 2012 - 07:07 AM

If you're getting errors, the code is definitely not correct.

This post has been edited by sepp2k: 15 April 2012 - 07:12 AM

Was This Post Helpful? 1
  • +
  • -

#3 Valiantangel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-April 12

Re: Is my code correct?

Posted 15 April 2012 - 07:14 AM

View Postsepp2k, on 15 April 2012 - 07:07 AM, said:

If you're getting errors, the code is definitely not correct.


Thanks for your unintelligent reply.If i knew i would not be here.
Was This Post Helpful? -1
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2013
  • View blog
  • Posts: 3,038
  • Joined: 21-June 11

Re: Is my code correct?

Posted 15 April 2012 - 07:20 AM

I'm sorry, I may have misunderstood your initial post. It sounded as if you did know that the code was producing errors. So let me be clear:

No, your code is not correct. If you try to compile it, it will produce an error message telling you that x is not a valid suffix for integer constants. In addition to that syntactic error it also contains semantic mistakes: For example ^ in C is bitwise-xor, not exponentiation. Plus you're using x uninitialized (or you will be once you fix the part where you use it as an integer suffix).
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1