Help Array and Loop

This is a discussion on Help Array and Loop within the C Programming forums, part of the General Programming Boards category; Hi there guys need a little help and direction on this. I have to write a program that asks the ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    29

    Help Array and Loop

    Hi there guys need a little help and direction on this. I have to write a program that asks the user to enter 10 double numbers and do the below.

    -Store information in a 10-element array.
    -Display 10 numbers back to the user.
    -use loops

    here's what I have so far
    Thanks

    Code:
    int main()
    {
        char astring[10];
        int i = 0;
    
        printf( "Please enter 10 double numbers: " );
        scanf( "%s", astring );
        for ( i = 0; i < 10; ++i )
        {
        if ( astring[i] == 'a' )
        {
    
    
       printf( "The 10 double numbers you selected where, %s", astring );
    
       getchar();
    }
    
    }
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Are "double" numbers supposed to be double precision floating point numbers?

    If so, you probably don't want a "char" array, and consequently not input using "%s". "%lf" will be the choice to use.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    29
    Quote Originally Posted by matsp View Post
    Are "double" numbers supposed to be double precision floating point numbers?

    If so, you probably don't want a "char" array, and consequently not input using "%s". "%lf" will be the choice to use.

    --
    Mats
    Yes double precision floating point numbers.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So modify your source as I described - post it again if you need more help [but not the same as above, because that means you are not trying yourself to solve the problem].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    29
    ok thanks

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    "&#37;lf" will be the choice to use.
    But only for scanf(). printf() takes %f for floats and doubles; scanf() takes %f for floats and %lf for doubles.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For loop through a 2D array - just for select rows
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 04-17-2009, 09:34 AM
  2. Need loop to copy chunks from byte array
    By jjamjatra in forum C# Programming
    Replies: 2
    Last Post: 03-05-2009, 05:42 AM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01:13 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM

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