Thread: Not sure how to do this, but Im sure you know how

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167

    Question test

    Ok, lets say I have ten stones. In addition I have one pocket. I could easily write a program which lets me pick up stones, put them in a pocket, and take them out. In addition such a program could keep track of how many stones were in the pocket, and how many weren't.

    But lets say I have two pockets, in that case I would have to do:

    Code:
    int numberofstonesinpocketone=0;
    int numberofstonesinpockettwo=0;
    But what if, I had x pockets. It would be easy to write code which lets me change the number of stones in my system, a simple

    Code:
    cin>>numberofstones;
    would accomplish that, but what if I don't know the number of pockets? I could do:

    Code:
    int numberofstonesinpocketone=0;
    int numberofstonesinpockettwo=0;
    int numberofstonesinpocketthree=0;
    int numberofstonesinpocketfour=0;
    ...
    int numberofstonesinpockettenbillionthreehundredthousandandfiftytwo=0;
    int numberofstonesinpockettenbillionthreehundredthousandandfiftythree=0;
    which although a tedious task, could be done...however, the problem with that method is that I am then left with using excessive memory, if i make my program capable of knowing the contents of 50 pockets then, if I only use 15 pockets, I am wasting memory remembering that 45 pockets aren't being used.

    What can I do? I suspect that objects are what I need to use but it seems every tutorial I find doesnt really address any of my questions, always focusing on some other aspect of the concept.

    It would be beneficial if a group of users worked together to write tutorials, referring those who ask questions to the tutorials, and improving the tutorials over time.
    Last edited by Noobie; 05-14-2003 at 12:12 AM.
    AIM: MarderIII

Popular pages Recent additions subscribe to a feed