true division in C ?

This is a discussion on true division in C ? within the C Programming forums, part of the General Programming Boards category; Hi there! This is my first post and I'm a complete noob to C, so please bare with me. I'm ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    23

    true division in C ?

    Hi there!
    This is my first post and I'm a complete noob to C, so
    please bare with me.
    I'm having an awful time trying to do true division.
    All my variables are int type but my result comes out to 0.

    I tried changing one of the variables to double but i'm getting compilation errors.

    Here is the original code:
    Code:
    #include <stdio.h>
    
    int main()
    {
    	int resgallons;
    	int currentppm;
            int  targetppm;
    	int result
    		printf( "Enter a 2 digit number: How many gallons are in you res?\n" );
    		scanf("%d", &resgallons);
    		printf("Enter you current PPM level.\n");
    		scanf("%d", &currentppm);
    		printf("Now enter your desired PPM level\n");
    		scanf("%d", &targetppm);
    	
    		  result = ( targetppm - currentppm) / targetppm * 8 * resgallons);
    		
    	
    		printf("%d", result);
    		return 0;
    	
    }
    Then I tried this:
    Code:
    #include <stdio.h>
    
    int main()
    {
    	int resgallons;
    	int currentppm;
            int  targetppm;
    	int result
    		printf( "Enter a 2 digit number: How many gallons are in you res?\n" );
    		scanf("%d", &resgallons);
    		printf("Enter you current PPM level.\n");
    		scanf("%d", &currentppm);
    		printf("Now enter your desired PPM level\n");
    		scanf("%d", &targetppm);
    	
    		 double result = ( (double)targetppm - currentppm) / targetppm * 8 * resgallons);
    		
    	
    		printf("%lf", result);
    		return 0;
    	
    }
    But this gave me compilation errors.
    Could someone point me in the right direction.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    You forgot a ; after
    Code:
    int result
    Also, you first declare result to be an int, and then proceed and redeclare it to be a double.
    Last edited by Memloop; 12-03-2009 at 09:46 PM.

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    In both of your codes you are also missing a bracket in the "result=" line. Other errors are as Memloop pointed out.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    23
    AHA! I knew it.
    Complete noob mistakes.
    Thanks for the help guys.
    Everything is cool now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 06:57 AM
  2. Socket class OOD
    By lord mazdak in forum C++ Programming
    Replies: 6
    Last Post: 12-17-2005, 12:11 AM
  3. help with MAZE
    By jpcorzo in forum C Programming
    Replies: 3
    Last Post: 11-24-2005, 12:47 AM
  4. Can someone help me with this console app please?
    By Marcos in forum C++ Programming
    Replies: 4
    Last Post: 07-26-2003, 07:04 PM
  5. Problems with resource files
    By Unregistered in forum C++ Programming
    Replies: 18
    Last Post: 08-31-2001, 08:45 AM

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