Thread: Anyone see why this doesn't work?

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    6

    Anyone see why this doesn't work?

    I'm new to C programming, but not to programming. Can anyone see why this code isn't working? It seems to be the simplest program in the world, but it always returns a product of 0.00000. If anyone can spot what I'm doing wrong, please reply.

    Thank you.

    tzuch


    Code:
    #include <stdio.h>
    
    float x,y, prod;
    
    float fmu(float a, float b);
    
    main()
    {
    	puts("Enter two floats to multiply");
    	scanf("%f %f", &x,&y);
    
    	prod=fmu(x,y);
    
    	prfloatf("\nThe following is the product...%f", &prod);
    
    	puts("\n\n\nEnter a single digit to exit");
    	scanf("%d", &x);
    
    	return 0;
    }
    
    
    float fmu(float a, float b)
    {
    	return (a*b);
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    What is prfloatf? And if it's anything like printf, then you should not be using the address-of operator (&) in that particular function call.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Removing the ampersand should do.
    lol .I think the OP should have used the search and replace option to replace int with float.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  4. #4
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    Quote Originally Posted by stevesmithx View Post
    Removing the ampersand should do.
    lol .I think the OP should have used the search and replace option to replace int with float.
    Haha. Now that you mention it, I think that's exactly what he did.

    Your main should be defined as int main(void), not main(). Also, to the OP, get away from using global variables. Define the variables in main(), and if you have to, pass the variables from your main to your function fmu().

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    6

    Thanks Guys!!

    Simple typos. I did a replace from int to float and the ampersand was incorrect.

    Guess I'll get new glasses!

    Thanks all.

    tzuch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM