Thread: trouble with my first c program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    2
    Thanks, I guess that works, Im sorry for not using the code tags. Im just wondering if there isnt another way of going about this?

  2. #2
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    You could try my snip function!
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    // Snip the double value of where you want it to be snipped
    double
    snip (double d,   // The decimal value we want to snip
          int dp)     // The decimal places of where to snip
    {
      // Bring the decimal number up to an integer of where we want to cut
      // And snip it
    
      d = floor (d * pow (10, dp));
    
      // Bring the integer back to a decimal by moving the decimal place back to the left
    
      d = d / pow (10, dp);
    
      // Successfully return the snipped version of the decimal
    
      return d;
    }
    
    int main (void)
    {
      // n = The number we want to snip
      // n2 = The result of the snipping
    
      double n = 3.14823723;
      double n2;
    
      // Snip the large decimal
    
      n2 = snip (n, 2);
    
      // Print out the results
    
      printf ("%f = ~%f\n", n, n2);
    
      // Return successfully
    
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having a bit of trouble with a binary search program
    By d-dub in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2006, 05:20 AM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM