Create array


how would you do this array?


The first Array will consist of the following

Array1 = A,B,C,D,E,F,G,H,I,J,K,L,M

The second

Array2 = 2,2,1,2,2,2,1

I will have a form with a dropdown textbox of Array1 so the user can select the desired
letter. Also they indicate from which start position they want from Array2

So basic example

User selects "A" and position 1 from Array2

So we start with "A" then

add "2" (from Array2) which outputs "C" (From Array1), ("C" is two away from "A" etc etc)
add "2" (from Array2) which outputs "E" (From Array1)
add "1" (from Array2) which outputs "F" (From Array1)
add "2" (from Array2) which outputs "H" (From Array1)
add "2" (from Array2) which outputs "J" (From Array1)
add "2" (from Array2) which outputs "L" (From Array1)
add "1" (from Array2) which outputs "M" (From Array1)

If a user selects a middle letter for example "G" and position 3 then the following occurs.

Start with "G"

add "1" (from Array2) which outputs "H" (From Array1), ("H" is one away from "G" etc etc)
add "2" (from Array2) which outputs "J" (From Array1)
add "2" (from Array2) which outputs "L" (From Array1)
add "2" (from Array2) which outputs "A" (From Array1), ("A" is two away from "L", going from left to right)
add "1" (from Array2) which outputs "B" (From Array1)
add "2" (from Array2) which outputs "D" (From Array1)
add "2" (from Array2) which outputs "F" (From Array1)

Regards

Geoff
closed account (o3hC5Di1)
Hi there Geoff,

Could you please be a bit more specific on what it is you're struggling with?

This seems fairly straightforward array-work to me, so maybe post the code that you have so far, relevant to this and we'll go from there?

All the best,
NwN

I will have a form with a dropdown textbox of Array1 so the user can select the desired
letter.


Do you want to make a GUI? Are you sure you want to use C++ for this?

As you can tell, I'm new to all this. The reason for the c++ question is I have downloaded some ipod devoloper software that works with windows.
The language used is c++. I thought I would give myself a basic project to start with and this is what I have come up with.

A simplified example of what I'm trying to do is

Imagine a clock with the hour hand only. first of all you select a number to start from (1,2,3,4,5,6,7,8,9,10,11,12)

Lets pick 5

Now we have another sequence of numbers., 2,2,1,2,2,2,1

So our first number is 5 which we are going to rotate clockwise using the each one of the second sequence

5+2=7

7+2=9

9+1=10

10+2=12

12+2=2 (Start from 12 add 2 = 2 on the clock)

2+2=4

4+1 = 5

So the end result would be 5,7,9,10,12,2,4,5

thats starting from 5 and using 2,2,1,2,2,2,1 as the rotating sequence.

Now we could also start at any point in the sequence also ,so we could start at the second "2"

Thanks

Geoff
closed account (o3hC5Di1)
Hi there,

Alright, you will need 2 arrays - one for the clock numbers and another for the sequence numbers:

1
2
int clock[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
int sequence[7] = {2,2,1,2,2,2,1};


You say you want to use a dropdownlist, which boils down to getting user input.
So the input from the user will probably be a number of the clock, stored in a variable.

Then you will need to traverse through the sequence array using a loop, so that for every sequence element there is an addition performed:

1
2
3
4
for (int i=0; i<7; i++)
{
    element-from-character-array + sequence[i]; //this is invalid off course, just to show the idea
}


Within this loop you will need to perform a check regarding the boundaries of the clock array, meaning that when the loop tries to goes beyond 12 in the clock array, it jumps back to 1.

I don't like to spoonfeed it to you because you'll learn more if you figure it out yourself.
If you're not sure about the things I used here, check out: http://cplusplus.com/doc/tutorial/
It has great sections on arrays and all the other basic stuff you need for this.

Let us know if you need any further help.

All the best,
NwN

Hi Thanks

Thats something to work with.

Regards

Geoff
Topic archived. No new replies allowed.