Thread: why I cannot compare the value?

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    21

    Question why I cannot compare the value?

    this a simple program to compare two numbers, but it cannot display the correct result, what I got is always "0.00". why?

    Code:
    #include<stdio.h>
    double small(double x,double y);
    int main(void)
    {
        double x,y;
        printf("ple enter number");
        scanf("%f %f",&x,&y);
        printf("the smaller number is %.2f", small(x,y));
        system("pause");
        return 0;
    }
    double small(double x,double y)
    {
           if(x<=y)
           return x;
           else
           return y;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >scanf("%f %f",&x,&y);
    The scanf format modifier for double is %lf.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  3. compare strings not working
    By gtriarhos in forum C Programming
    Replies: 7
    Last Post: 09-29-2005, 12:51 PM
  4. Help Writing My Own String Compare
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 04-07-2005, 09:44 PM
  5. String Compare Using Dynamic Arrays
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 03-31-2005, 08:01 PM