Need help with most basic arrays.

This is a discussion on Need help with most basic arrays. within the C Programming forums, part of the General Programming Boards category; Can someone please explain to me why this simple array program isnt able to store 10 array values from the ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    244

    Need help with most basic arrays.

    Can someone please explain to me why this simple array program isnt able to store 10 array values from the user? instead it asks for 11 values and then it outputs 10.

    My objective is to ask the user for 10 test scores and then print them out in reverse order.





    Code:
    #include <stdio.h>
    
    int main() {
    
    int index, array[10];
    
    printf("Please enter 10 test scores.\n\n");
        for (index=0; index<10; index++)
            scanf("%d\n", &array[index]);
    
    printf("Here are the scores in reverse order:\n");
         for (index=9; index >=0; index--)
             printf("%d  ", array[index]);
    
    system ("PAUSE");
    return 0;
    
    }
    Thank you.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Because you have an extra bit in your scanf:
    Code:
    scanf("%d\n", &array[index]);

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    244
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi-dimensional arrays - basic understandin
    By deadhippo in forum C Programming
    Replies: 4
    Last Post: 05-09-2008, 12:12 AM
  2. Basic Help with Arrays and Output
    By slowcoder in forum C Programming
    Replies: 15
    Last Post: 05-10-2007, 09:56 AM
  3. A basic Word Puzzle Algorithm
    By m0ntana in forum C Programming
    Replies: 5
    Last Post: 03-29-2007, 12:05 PM
  4. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM
  5. arrays arrays arrays....
    By Jan79 in forum C++ Programming
    Replies: 1
    Last Post: 11-11-2002, 06:16 AM

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