Function not working

This is a discussion on Function not working within the C Programming forums, part of the General Programming Boards category; This program should return the number of roots of a 2nd degree polynomial, but it always returns 2 roots, whatever ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    7

    Function not working

    This program should return the number of roots of a 2nd degree polynomial, but it always returns 2 roots, whatever coefficients I put.
    Whatīs wrong??

    Itīs in spanish, so RAICES=ROOTS, and disc means the discriminant of the equation (b^2 - 4*a*c).

    Thanks in advance.


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
      int raices (int a, int b, int c)
        {
        int x,y,z,disc;
        disc=((y*y)-(4*x*z));
        
        if (disc<0)
            return 0;
        if(disc==0)
            return 1;
        if(disc>0)
            return 2;
        
        }
    
    int main()
    {	
      int a,b,c;
      
      printf("a= ");
      scanf("%d",&a);
      printf("b= ");
      scanf("%d",&b);
      printf("c= ");
      scanf("%d",&c);
      printf("El polinomio tiene %d raices\n",raices(a,b,c));
     
      system("PAUSE");	
      return 0;
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    > disc=((y*y)-(4*x*z));
    Try it with a,b,c and not x,y,z
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    7
    excellent!

    Now I must think why it doesnīt work the other way...

    thanks!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21