Thread: Functions/code help!!

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    5

    Functions/code help!! Confused!!

    Devise a function my_min(x,y) that returns the smaller of two float values, and test the function with a driver. The driver should prompt the user for input and then display the value returned by the my_min() function.

    Notes:
    I am asking you to call the function my_min() instead of just min() to avoid any possible conflict with the min() function included with your C compiler, usually in stdlib.h.


    This is what I have so far

    Code:
    #include "stdafx.h"
    
    float my_min(float a, float b);
    int _tmain(int argc, _TCHAR* argv[])
    
    {
    
    float a,b;
    
    int x= 12.345;
    int y= 67.78;
    
    
    
     
    
    
       printf("Enter a value for x\n");
       scanf("%f", &a);
       
       printf("Enter a value for y\n");
       scanf("%f", &b);
       
       printf("The smaller of %f and %f is %f.\n", a, b, my_min(x,y));
    
       
     
    
    
    
    	return 0;
    }
    When working with float values so it should be:
    float my_min(float a, float b);

    and inside main() we use the variables x and y but inside my_min() we use a and b.

    I have created a function prototype which tells the compiler how to call the function, but I have not created the function.

    How do I do that


    Feedback and help would be greatly appreciated.
    Last edited by Makdaddy; 12-07-2010 at 11:00 PM. Reason: I took out my_min don't think I need that in there.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Function Code Help - C And C++ | Dream.In.Code
    You've been told about xposting before, and you still do it.
    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.

Popular pages Recent additions subscribe to a feed