Thread: Float and Double Numbers

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    13

    Float and Double Numbers

    Can sombedoy explain me how can I input float and double numbers in c?


    Can I put for exaple 0.54x10E45?

    Which must be the syntax of the input for single and double?

    thanks

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       double value;
       fputs("value? ", stdout);
       fflush(stdout);
       if ( scanf("%lf", &value) == 1 )
       {
          printf("value = %g\n", value);
       }
       return 0;
    }
    
    /* my output
    value? .54E45
    value = 5.4e+44
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    13
    Could you explain pīlease? Remember the question is how do the user can enter the float and double numbers? I did a program that sums two numbers but How can they ENTER on the keyboard the numbers if they need to add exponents?

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Look at the part in blue -- omit the x10 part of what you originally stated.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    13
    Thanks. Now what about if I need to valide the input?
    user can enter for example

    Please enter first value (examples value= .54E45 or value = 5.4e+44)

    If the user tries to enter something different than this kind of number how can I validate this?

  6. #6
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    FAQ > How do I... (Level 2) > Validate user input
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

  7. #7
    Registered User
    Join Date
    Apr 2005
    Posts
    13
    Thanks

  8. #8
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You're welcome.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. writing double quote & comma delimited files
    By emt in forum C++ Programming
    Replies: 5
    Last Post: 06-30-2003, 12:28 AM
  5. Configurations give different results
    By Hubas in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 11:43 AM