Thread: where is the error to make this program work ?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    where is the error to make this program work ?

    Hope you can help find the error. it wont calculate d and x properly

    Matthacker
    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    
    
    int main ( void )
    {
    	float a;
    	float b;
    	float c;
    	float d;
    	float x;
    	
    
    
    	a = 0, b= 0, c = 0, d = 0, x = 0;
    	x = (-b +- sqrt(d)) / (2*a);
    	d = (pow( b, 2)) - (4*a*c);
    
    
    	printf ( "please input the three numbers in the 2nd degree polynomium:");
    	scanf ("%f%f%f", &a,&b,&c);
    	printf ( " the polynomium is:" );
    	{
    	if ( a < 0 )
    		printf("%fx^2",a);
    	else
    		printf("%fx^2",a);
    	if ( b < 0 )
    		printf("%fx",b);
    	else
    		printf("+%fx",b);
    	if ( c < 0 )
    		printf("%f",c);
    	else
    		printf("+%f",c);
    
    
    	printf ( " = 0 \n");
    	}
    	
    	printf (" diskriminanten er: %f\n", d);
    	printf(" x er:%f",x);
    
    
    	return 0;
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by matthacker View Post
    Hope you can help find the error. it wont calculate d and x properly
    That's because you are trying to calculate your results before you know what values they operate upon.

    Move lines 18 and 19 to line 42.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    thanks

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    No worries... Just remember the cardinal rule when programming...

    Compilers are STUPID... you gotta tell them *everything* and in the right order, if you want to get the correct result.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I fix this to make the program work?
    By Xpl0ReRChR in forum C Programming
    Replies: 2
    Last Post: 11-17-2011, 12:13 PM
  2. Correction needed to make the program work?
    By ljgerr93 in forum C Programming
    Replies: 4
    Last Post: 10-17-2011, 12:59 PM
  3. How to make the following program work?
    By lijr07 in forum C Programming
    Replies: 2
    Last Post: 06-24-2011, 09:23 AM
  4. How can I make this program work? Problem with arrays
    By babe20042004 in forum C++ Programming
    Replies: 1
    Last Post: 12-21-2009, 07:14 PM
  5. Replies: 2
    Last Post: 03-25-2002, 05:49 AM