i'm a new programmer and i need help

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: i'm a new programmer and i need help

1. Registered User
Join Date
Feb 2004
Posts
1

## i'm a new programmer and i need help

the boss has a large gun that can shot projectilesat various heights. for each shot stunman can either stand still or jump. if he stands still and the shot is height 1 or 2, then he gets hit. if he jumps and the shot is at a height above 2, then he is also hit. Otherwise, he is not hit. Given the height of each shot and a sequence of jumps. how many hits will stunman take.

the input integer() pattern is the pattern of heights at which the shots are being fired. each element of the pattern between 1 and 7, inclusive. The input string jumps is the sequence of jumps that stunman will attemp, 'J' means jump and 'S' means he will stand still.

The methopd should return an integer representing the number of times stunman is hit.

I know the function looks something like this

Public Function hitTaken(pattern as Integer(),jumps as String)as Integer

I wouldn't be here if i haven't tried all the other avenues first.
i've searched the web and books with no luck. i know somewhat what it should look like but can't get it to work.
Last edited by newbee; 02-06-2004 at 11:48 AM.

2. Senior Member
Join Date
Nov 2003
Location
Portland, OR
Posts
8,387
Hi, newbee: If we do your homework for you, how will you learn? Why don't you try to solve the problem first, and ask for help if you get stuck?

I'll give you a hint: VB's Rnd function can generate a series of random numbers between 1 and 7. Try looking up the function in VB's online help, or searching the Web for examples of how to use the function.

3. I do not think searching the web will help you in this case...

You have an array of interers, right? For each elements, you have a hit if the value is less then 3 and the guy stay still, or if the value is greater than 2 and the guy jumps. Did I get this straight?
Now, write a nice for loop for each element of the array (look at ubound and lbound) and implements the above statement using a sequence of if's.
If you already have the input parameters because someone is passing them to you, you are home free. Otherwise follow Phil suggestion and generate them randomly.
Because the probabililty that the boss shots low is 2 out of 7, I suggest to jump to survive...

Everyone was a newbee,
Marco

4. Senior Member
Join Date
Nov 2003
Location
Portland, OR
Posts
8,387
> I know somewhat what it should look like but can't get it to work.

In that case, why don't you post the code you have and explain how it's not working. Perhaps we can help you find the problem without doing the assignment for you.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise