definition and statement?

This is a discussion on definition and statement? within the C++ Programming forums, part of the General Programming Boards category; greetings, i am to write a definition and statement to construct a given array. 1. an array whosw indices are ...

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    definition and statement?

    greetings,

    i am to write a definition and statement to construct a given array.

    1. an array whosw indices are the integers from 0 thru 99 and in which the value stored in each array element is the same as the index.

    Is my answer wrong???

    Code:
    array[99];
    for(int i = 0; i < 99 i++)
    	[i] = array[i]
    I am
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    try this...
    im still learning c++ though, so not sure if it will work...

    Code:
    array[100];
    
    //use a counter
    //switch the [i] = array[i] statement around, and take the brackets around i out on the side that has i by itself
    //try that and happy programming...

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Re: definition and statement?

    array[99];
    (1) You haven't specified any datatype. Use int array[99]; since you should have an array of integers.

    (2) 0 - 99 is 100 elements, not 99. So change [99] to [100].

    for(int i = 0; i < 99 i++)
    (3) You forgot a semicolon there, after the 99.

    [i] = array[i]
    (4) Nope, array[i] = i; would be more correct. On the left side of the assignment operator is the variable where you store the value (evaluated expression) which is on the right side. Since it's an array, you have to specify an index via the [i].
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Code:
    int array[99];
    
    for(int i = 0; i < 99; i++)
    {
        array[i] = i;
    }
    
    // just to check its all been done properly...
    for(int j = 0; j < 99; j++)
    {
        cout << array[j];
        cout << "\n";
    }

  5. #5
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Beaten!!

  6. #6
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Talking

    Thanks everyone for the input!
    cj
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack operations from switch statement elements
    By mlsrar in forum C Programming
    Replies: 15
    Last Post: 10-02-2008, 02:12 PM
  2. Replies: 3
    Last Post: 10-02-2007, 10:12 PM
  3. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-31-2006, 12:59 AM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 01:22 PM
  5. functions and switch statement
    By rmathus in forum C Programming
    Replies: 2
    Last Post: 11-29-2003, 03:24 PM

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