JasonHippy 739 Practically a Master Poster

OK, I know it's been a while since I originally posted this and I've marked the thread as solved, but this is a valid bug in wxPython....So here's a quick update!

I finally managed to get onto the wxpython.org site to report the bug today. (All of the wxpython/wxwidgets websites were down when I originally discovered this bug back in June and I haven't tried any of their websites for a while, so I completely forgot about reporting it until today!)

Anyway, I've taken a quick look at the current python source code in their svn repository and the issue is still there, so nobody else has reported/fixed it yet!

My bug report ticket number is #11255 (http://trac.wxwidgets.org/ticket/11255)

Hopefully the bug will be accepted and fixed for a future release of wxPython, but in the meantime if anybody has problems with this bug then by all means use the fix I documented in my original post.

I'll keep an eye on this and keep you all posted!
Cheers for now,
Jas.

Ene Uran commented: thanks for the bug fix! +9
JasonHippy 739 Practically a Master Poster

Awesome I like it just one question why does the line below have datetime twice?

d = datetime.datetime.strptime(userIn, "%d/%m/%y")

It's the only way I could access the strptime function.
The first datetime refers to the datetime package, the second refers to the datetime class.

In my import I could have used something like:

import datetime as dt

This gives the datetime package an alias (dt). So to call the strptime function I'd need to use:

dt.datetime.strptime(userInput, pattern)

So my strptime function call breaks into the following parts:
packageName.className.function(parameter1, parameter2)
or:
datetime.datetime.strptime(userInput, "%d/%m/%y")

Hope that clarifies things for you!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

hi,
I just created this awesome python application and i want to spread it around, but every one has python.
I was just wondering if I could compile python source into a linux executable like py2exe, and then compile the executable into a .deb installer file.

any help would be appreciated.
thanks, The-ITu

There's a python library called 'Freeze' which can be used to create linux executables from python scripts. I don't think it's particularly well known, but I think it's been around longer than py2exe, so you could say that py2exe is the windows version of Freeze! heh heh!
I've not used Freeze yet, but I intend to eventually!

Anyway, check it out here:
http://wiki.python.org/moin/Freeze

As for creating .debs I've not had a go at it yet (I'm still working on my first few pet projects on Ubuntu), but I'm sure that there is tons of info online..So google is probably your best friend there!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

OK, well...I'm not familiar with this code, so I don't know exactly where it's from but:

DECLARE_STDCALL_P(struct hostent *)   gethostbyname(const char*);

breaking it down into three parts:
DECLARE_STDCALL_P is some kind of macro...Offhand I'm not sure exactly what it does...probably registers the function with some system mechanism or other..
(struct hostent *) - I think this is the return type of the function, a pointer to a struct....saying that the fact it's in brackets could mean that it's a parameter to the macro...Either way, with or without the macro, this is almost certainly the return type!

gethostbyname(const char*); - The easy bit. This is definitely the name of the function and its parameter list.

As for:

unsigned long PASCAL inet_addr(const char*);

I'm not entirely sure, but I think the return type is an unsigned long, but in PASCAL format....Perhaps inet_addr function makes some kind of external function call to an older part of the system that was written in pascal and it's return value is based on it's call to said external function??

I know in windows there are (or at least were) a lot of external functions in .dll's and libraries that were written in PASCAL (Not sure if many are left nowadays), So it's a possibility!

I'm sure one of the more senior programmers here can give you a more concrete answer!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

hmm, why thank you very much...:)

Is the problem solved?? ;)

JasonHippy 739 Practically a Master Poster

Firstly 'input' is a reserved word in python, it's used to get input from the user, (rather like raw_input!). So that's why this line of code fails to do anything:

input = raw_input("Type Date dd/mm/year: ")

Change your variable 'input' to something like 'userInput' or just anything that isn't a reserved word and you will get your prompt!

Secondly...No I don't think that strptime will work used like that! if your users enter anything other than yy-mm-dd, it will bomb out with an error!
But if you use a try: except: block inside a loop, you should be able to get the user to repeatedly enter the date until the format is correct!

Check this out:

import datetime
def ObtainDate():
    isValid=False
    while not isValid:
        userIn = raw_input("Type Date dd/mm/yy: ")
        try: # strptime throws an exception if the input doesn't match the pattern
            d = datetime.datetime.strptime(userIn, "%d/%m/%y")
            isValid=True
        except:
            print "Doh, try again!\n"
    return d

#test the function
print ObtainDate()

I've not done any exception handling code for a while, but there should be a way of outputting to the user the reason that the exception occurred.

I'll leave that up to you to look up!

Cheers for now,
Jas

JasonHippy 739 Practically a Master Poster

So what's the difference between:

void foo(int(&A) [])

void foo(int A[])

If the contents of array A need to be modified by the function foo, which of the two is the correct usage?

Thanks.

As far as I understand it, they are both valid and correct.
When passing an array via a reference:

void foo(int (&A)[10])

The only prerequesite is you need to know the dimensions of the array upfront.

But if you pass the array by value:

void foo(int A[]);

Because it's an array you're passing in, Its basically the same as passing a pointer. An array object contains the memory address of (and therefore a pointer to) the first position in the array.
This way you don't need to know the size of the array upfront. (That's not to say that the size of the array isn't important...Don't go indexing out of bounds or anything. You just don't need to specify the size of the array in the function prototype!)

So which you choose really depends what you're trying to do I guess!

Whereas if you were trying to pass a large class object to a function you could
pass in the following ways:
e.g.

void foo(CLargeClass myLargeClass); // pass by value
void foo(CLargeClass *myLargeClass); // pass by pointer
void foo(CLargeClass &myLargeClass); // pass by reference

Passing by value in this case would incur a performance hit because normally; passing by value creates a copy of the object …

JasonHippy 739 Practically a Master Poster

Hmm, your after fixing your originally posted code (which you've already done)...
When running the code I got an index out of bounds error..
So I've made a minor alteration..Not sure if you've already found and fixed this but...

import math

def polyPerimeter(xyList):
    perim = float(0)
    count = len(xyList)-1 # len(xylist) caused an index out of bounds error for me!
    b = 0; db = 1
    while b < count:
        tempDist = math.sqrt(math.fabs((float(xyList[b+1][0]) - float(xyList[b][0])))**2 + math.fabs((float(xyList[b+1][1]) - float(xyList[b][1])))**2)
        perim = perim + tempDist
        b += db
    # finally add the distance between the first and last points...
    tempDist = math.sqrt(math.fabs((float(xyList[0][0]) - float(xyList[count][0])))**2 + math.fabs((float(xyList[0][1]) - float(xyList[count][1])))**2)
    perim+=tempDist
    return perim

# crap I added to test the function
myList = [[0,0],[4,0], [4,4], [0,4]]
perimeter = polyPerimeter(myList)
print "Perimeter is:", perimeter

I've also used fabs to ensure that the distances are all positive and altered the algorithm to include the length between the first and last items in the list.
Just thought I'd mention it!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

OK, I started working on this when I saw your original post. But since I started, you made your second post. So I've modified it a little to give the line numbers; but I've not got it to output the character position yet!

I've done the search using the re module (regular expressions).

Here's the code I've got so far...It only works if all lines in birthday.txt end with a newline! Otherwise the last line gets a character removed by my code!

Anyway, this is what I've got so far: (not quite the same as yours but it kinda does the job!)

import string
import re

def find():
    # read both text files in their entirety...
    piDigits = open("pidigits.txt").readlines()
    birthdays = open("birthday.txt").readlines()

    # iterate through the dates
    for date in birthdays:
        wasFound=False

        # build a search string
        # need to strip out the newlines...
        # ensure each line in birthday.txt ends with a newline
        # otherwise the last birthday will have the last digit removed!
        searchString=""
        for idx in range(0, len(date)-1):
            searchString+=date[idx]

        # as long as we have exactly 6 chars in the search string
        # we can continue!
        if len(searchString)==6:
            print "\n\nSearching for", searchString, ":"
            # iterate through the piDigits and use the re module
            # (Regular expressions) to see if the birthday is found
            count=0
            for line in piDigits:
                count+=1
                result = re.search(searchString, line)
                if result: # if found, set flag and output.
                    wasFound=True
                    print "The birthday", searchString, "was found at line ", count …
JasonHippy 739 Practically a Master Poster

The description of your problem is at best vague and at worst confusing...Being able to see the code that's actually causing you the problem would help!
So if you could post some code it would help us to help you! (Just don't forget the code tags!)


Also, regarding your question about void main vs int main....Well that particular issue has been discussed numerous times here on Daniweb.
Take a look at:
http://www.daniweb.com/forums/thread109415.html
or:
http://www.daniweb.com/forums/thread78955.html

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

No probs.
I've downloaded the files, but my Wife's currently working on the windows machine. So I'm on my Linux box at the moment (no flash!), but I'll take a look at the files at some point this weekend and I'll let you know what I've come up with!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Ah, yes, sorry if I confused you there...Perhaps I misunderstood something!

You said something about when the panorama had loaded, you wanted a button to appear so you could click on the button and the panorama would disappear.

So after the panorama creation code, the following code dynamically creates an additional button using a button in your movies library....

_parent.attachMovieClip("btn_library_name", "btn_instance_name", _parent.getNextHighestDepth() [_x=50, _y=50]);

Before I go much further, I'll explain a bit about the library...
You know when you click on an object and press F8 (or right click on an object and select 'convert to symbol'), you get that dialog appear asking what type of symbol you're creating (graphic, movieclip or button)??...

Whenever you do that, a new symbol is added to the library.
Whatever you enter in the 'Name:' field of the dialog is what the new symbol will be called in the library.

Now, as mentioned; with objects in the library, you can create them dynamically at runtime. So instead of dragging items out from the library and placing them onto the stage in your .FLA, you can actually create them using actionscript..

But you can't do it with any library objects by default. What you first need to do is set the appropriate linkage settings for the library items you want to create dynamically.

In order to be able create an instance of a library item using code:
Open the library
Right click on …

JasonHippy 739 Practically a Master Poster

What about replacing the backslashes with forward slashes?
So wherever there was a single backslash, replace it with a forward slash. That should also fix your problem!

I know typically in Windows, filepaths look like this:
C:\SomeDirectory\SomeFile.ext

But in C++ forward slashes are also acceptable for file paths..
c:/SomeDirectory/SomeFile.ext

The obvious reason for using forward slashes is to avoid the problems with backslashes in C/C++ strings.

A backslash in a C/C++ string is an escape sequence for special characters like '\n'. Double backslashes '\\' is the escape sequence used to put a single backslash into a string!

So instead of replacing the single backslashes with doubles; replace them with forward slashes and you can circumvent the entire problem.. I use forward slashes all the time in file paths and have never experienced any problems!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Assuming that the .swf for your panorama is an external .swf that you are trying to load into your main.swf...

Perhaps try something like this inside your on(release) function...

on(release)
{
	// Create a blank movieclip to load the external clip into...
	// we'll create it outside of your button in the _parent clip
	_parent.createEmptyMovieClip("external_mc", _parent.getNextHighestDepth());

	// set it's x and y coords... 
	_parent.external_mc._x=300; 
	_parent.external_mc._y=300; 

	// Now load the external .swf into the blank clip (external_mc)
	_parent.external_mc.loadMovie("foyer_pano.swf")

	// Now would be a good time to add an instance of a button to remove the panorama clip
	// we'll add it to a new layer in the parent of this button...... 
	// Note: you'll need to have your button item set up in your library so it's linkage 
	// is set to 'export for actionscript'
 
	// The code looks something like this if memory serves......
	_parent.attachMovieClip("btn_library_name", "btn_instance_name", _parent.getNextHighestDepth() [_x=50, _y=50]);

	// finally we'll set up some script on the 2nd buttons onRelease function
	// to remove the panorama and itself from the stage.
	_parent.btn_instance_name.onRelease = function()
	{
		removeMovieClip(_parent.external_mc);
		removeMovieClip(this);
	}

}

That's about the simplest thing I can come up with based on the info you've given.

If the panorama is a really large .swf that might take a while to load, you could perhaps use a MovieClipLoader. But give the above code a go first and let me know how you get on!

Cheers for now,
Jas.

p.s. I've not done any AS2 for …

JasonHippy 739 Practically a Master Poster

OK, well there are a few problems with your error checking/input validation. Also your loops are a bit wierd, the program continues after it guesses correctly. And the number guessing algorithm looks a bit dodgy too!

Here's a slightly improved version of your program.
Changes made:
I've used a very simple binary search algorithm to guess the users number. Hopefully the comments in the code will clarify the logic used!

I've fixed your main while loop, so it loops until the CPU makes a correct guess or the CPU runs out of guesses.

I've also strengthened the input validation by adding an additional nested while loop. So the user is repeatedly asked if a guess is correct until they provide a valid answer..

I'll post the code twice. The first version I've commented heavily so you can see what's going on in my added code. The 2nd will be without the comments, so the actual code should be a bit more readable!

Here's the heavily commented version:

#print instructions to the user
print 'Guess a number from 1 to 1000 and I will guess what it is in less than 10 tries! After each guess, tell me either "correct", "lower", or "higher".'

#here's the guesser...

def guess():
    guesses = 0
    low = 0
    high = 1000

    isCorrect=False # boolean sentinel flag..Has the user said that a guess was correct?

    # while guesses are < 10 and user hasn't said that a guess …
JasonHippy 739 Practically a Master Poster

OK, here's a very simple class and some code to test it, based on what you posted previously!

# here's a simple class
class MyClass:
    # class constructor/initialisation
    # if no string is passed, defaults to an empty string
    def __init__(self, aString=""):
        self.myString = aString

    # addText function
    def addText(self, appendedText):
        self.myString += appendedText

    # getString function - returns the current string
    def getString(self):
        return self.myString

# Now lets test the class...
print "Testing the class [passing a literal string to the  constructor]"
# Create an instance of the class, passing some text
myObject = MyClass("Blah blah blah...")
print myObject.getString() # Lets see what we've got

# now lets add some text by passing a literal string to addText...
myObject.addText("More text...")
print myObject.getString() # Now what do we have?

# now lets create a string object and pass it to addText...
anotherString = "Yet more text!"
myObject.addText(anotherString)
print myObject.getString() #  Now what've we got?

print "\nTesting the class [passing no parameters!]"
myOtherObject = MyClass()
print myOtherObject.getString() # This should print a blank line

# now lets pass addText the string object we created earlier!
myOtherObject.addText(anotherString)
print myOtherObject.getString() # now what have we got?

The addText and getString functions speak for themselves..They're pretty straightforward.

The __init__ function is the important bit here, this is what gets called when you instantiate the class. You perform any initialisation for your object here.

The other thing of note is 'self', which is kinda like the 'this' pointer in C/C++/Actionscript (and Java?.. …

vegaseat commented: now that is class! +15
JasonHippy 739 Practically a Master Poster

I was driving past a local special-needs school the other day and I noticed a sign facing the road that says 'SLOW CHILDREN'....And I thought, "Well, that can't do much for their self-esteem can it?" - Jimmy Carr

JasonHippy 739 Practically a Master Poster

I Have a Degree in Liberal Arts; Do You Want Fries With That?

JasonHippy 739 Practically a Master Poster

Here's something I just knocked up in a few minutes....This isn't exactly what you're doing, but it should give you a few ideas to use in your game.

My variant uses one tower. The player starts with 50 blocks in their tower.
The computer will then draw random cards (valued from 1-10) and will then add or remove blocks from the players tower until the maximum or minimum number of blocks has been reached.
Odd numbered cards remove blocks, even numbers add blocks. Cards are worth 5,10,15,20 or 25 blocks.

I'm not sure how au fait you are with python, so I've used some pretty simple code and commented it heavily....

Without further ado, here's the listing:

import random

# set up our maximum and minimum number of blocks
MAXBLOCKS=100
MINBLOCKS=0

# set up the initial number of blocks in the tower
userBlocks=50

# count how many cards are dealt in the game
dealCount=0

# some instructions:
print "The aim is to get 100 or more blocks in your tower."
print "The computer will randomly select a card for you (1-10)."
print "The value of the card will affect your towers height."
print "Even numbers add blocks, odd numbers remove blocks."
print "Cards are worth the following:"
print " Card value    -    Block Value"
print "================================"
print "    1,2        -     +/- 05"
print "    3,4        -     +/- 10"
print "    5,6        -     +/- 15"
print "    7,8        -     +/- 20"
print "    9,10       - …
JasonHippy 739 Practically a Master Poster

I'm having a bit of an industrial/electronica day today:
I loaded my industrial playlist and set it to random.

So I've had a mad mix of the likes of Ministry, Front Line Assembly, Skinny Puppy, KMFDM, Laibach, DAF, NIN, Gary Numan, Throbbing Gristle, Kraftwerk, Godflesh, Merzbow, Navicon Torture Technologies, Whitehouse, Zombie Nation, Venetian Snares, Boyd Rice/NON, Front 242 and Coil to name but a few this morning...

Mellowed out over lunch with a bit of Rondellus ('Sabbatum' - Black Sabbath covers played on medieval instruments, with vocals in latin...Amazing album!) and Rodrigo e gabriela's rendition of Metallicas 'Orion'.

Back to more industrial noise now...
The collected works of Jim Thurwell are on the menu for this afternoon (Foetus, Wiseblood etc.. )...Probably followed up by a bit of Berzerker in the car on the way home!

JasonHippy 739 Practically a Master Poster

Hi folks
I have just completed my first programme with help from yourselves.
I cant understand why the code , if x ==1 or 2, wouldn't work in my programme below

# Convert C to F or F to C and return with result

select = True
while select:
    x = int(raw_input ('To convert Celsius to Farenheit, enter 1\nTo convert Farenheit to Celsius, enter 2\n'))   
    if x == 1 or x == 2:
        select = False
    else:
        print 'Only options are 1 or 2'            

#Convert C to F
if x == 1:
    def Tc_to_Tf ():        
        Tc = input ("What is the Celsius Temperature ?   " )
        Tf = 9.0/5.0 * Tc + 32
        return Tf
    Tf = Tc_to_Tf ()
    #.2f instructs Python that placeholder holds float number with 2decimal places. 
    print 'The temperature is %.2f Degrees Fahrenheit' %(Tf, )
        
#Convert F to C
if x == 2:
    def Tf_to_Tc ():
        Tf = input ("What is the Fahrenheit Temperature ?   " )
        Tc = (5.0/9.0)*(Tf - 32)
        return Tc
    Tc = Tf_to_Tc ()
    print 'The temperature is %.2f Degrees Celsius' %(Tc, )

Many thanks in anticipation. I included the whole programme as I would value any comments on my methods.
Graham

I can't see a problem with the code you've posted!

However if you were using this before:

if x==1 or 2:

Then as gerard has said, the if statement would always evaluate to True...

for example if the user entered '4' as their first choice, …

sneekula commented: great explanation +8
JasonHippy 739 Practically a Master Poster

This block of code looks like it's presenting the problem:

elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    elderly.moveup()
                if event.key == pygame.K_DOWN:
                    elderly.movedown()
                if event.key == pygame.K_RIGHT:
                    elderly.moveright()
                if event.key == pygame.K.LEFT:
                    elderly.moveleft()
            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_UP or event.key == pygame.K_DOWN or event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
                    elderly.movepos = [0,0]
                    elderly.state = "still"

If you take another look at your Elderly class, it doesn't have any methods defined called moveright(), moveleft(), moveup(), or movedown(), or properties called movepos or state for that matter either!

So you'll need to define them in your Elderly class.
e.g.
inside your definition of Elderly you need to define the moveup function (and the other missing functions like this):

def moveup():
            #TODO: add code to move your elder upwards

        def movedown():
            #TODO: add code to move your elder downwards

            # etc etc.....

You should also add and initialise the missing properties (movepos and state) in the __init__ function for the Elderly class!

Give that a go and let us know how you get on!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Ooops, I didn't notice that at the bottom of the post!

Hmm..It's been quite a while since I did any .NET stuff with C++.

I can't find any of my old managed code, but I know I've had to do similar conversions in the past. I think this may've been one of the ways I've used....

String URL;

// some code.....Assume URL eventually gets populated with something!

// Create a CString to use as a parameter using URL....
CString urlParam(&URL); // don't forget to #include <atlstr.h>
  
// Above: If memory serves, from VS7 onwards CString can take a pointer to a system::String as a parameter in it's constructor when using the managed extensions... But I could be wrong!

// now call shellexecute passing the CString version of URL (urlParam)..
ShellExecute(NULL,"open",urlParam,NULL,NULL,SW_SHOWDEFAULT)

Alternatively, try taking a look at the following article:
http://support.microsoft.com/?id=311259

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Ok.
As you're using a std::string to store your URL and ShellExecute is expecting a pointer to a C style string (LPCSTR) as a parameter, you simply need to change your ShellExecute call to:

ShellExecute(NULL,"open",URL.c_str(),NULL,NULL,SW_SHOWDEFAULT)

The c_str() function of the standard library std::string class returns the contents of the string as a C style string...Which is exactly what ShellExecute is expecting as a parameter. That should fix your problem!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

By the way, is your band on any sites? I'd love to hear how you play.

There are a handful of tracks uploaded to the Downfall myspace page. There's a link to it posted on my Daniweb user profile.

J.

JasonHippy 739 Practically a Master Poster

That sounds pretty complicated, and not exactly the best way to create music. Thanks for enlightening me with that info though.

Heh heh, well...It's not ideal...It sounds a lot more long-winded than it actually is though...We meet up once a week for rehearsals (usually Sundays), but sometimes someone will come up with something on a Monday or a Tuesday and start the ball rolling....By the following weekend, we've usually got a rough demo of a complete new song and a new song to rehearse when we meet up for rehearsal!

So by the following rehearsal, we all know exactly what we'll be playing on the new track.
So could be described as a rapid music development technique heh heh! (If somewhat convoluted!)

JasonHippy 739 Practically a Master Poster

I'm always up for playing music with other talented musicians.
Not quite sure how it would work without ever seeing each other though...??

Well, my own band use this unconventional songwriting method from time to time:
1. One of our guitarists comes up with a few riff ideas (or occasionally a whole song).

2. They record their parts into Cubase (or sometimes they use Audacity) on their PC's (while playing along with a metronome) and export a .wav.

3. They then email the .wav and cubase project to me (or if using Audacity, they'll send the .wav and tell me the tempo and the times of any tempo changes). I then use Drumkits from hell to program a few different drum parts for each section and export a .wav mixdown of the guitar and drums.

4. We then decide (via heated debates using email / IRC / Ekiga) which of my drum grooves fit the riffs best (Most of the time we'll use whatever I come up with first, but sometimes we'll try a few different ones!) and then we finalise the arrangement of the song.

5. I then go back and finalise the drum-parts, the guitarists will re-arrange and re-record their parts (if necessary), we put all of that together and pass a mixdown of guitar and drums to our bassist and vocalist (with any necessary information on the key used). They in turn will listen to the tracks and write and record …

JasonHippy 739 Practically a Master Poster

I play the radio - I was first chair sax in HS until someone else learned how to play. I tried flute for a while but it is odd - I can hear the difference between notes but the differences do not mean anything to me.

So - have any of you drummers/percussionists heard of Ainsley Dunbar?

Yes, he's one of the lesser known session drummers. Lesser known in the sense that hardly anybody mentions him. He's not a household name or anything, not many drummers will cite him as an influence. But without knowing it, his playing is probably on a lot of tracks that other drummers are influenced by.

But he's a drummer who's worked with more legendary bands and artists over the years than most other drummers have had hot dinners!

An unsung hero if you will!

JasonHippy 739 Practically a Master Poster

Hey, we've almost got enough people in this thread to start up an internet based all-geek band here on Daniweb!

Me 'n Crazzy Cat can share drum / percussion duties,
Serkan Sendur and Mosaic Funeral on Guitar,
Grn Xtrm on Bass,
and Rashakil Fol and PaulThom on Piano/keyboard.

Mosaic can also do his best Trent Reznor impression with his miscellaneous electronic noise making equipment.

Now all we need is a vocalist and some ideas on musical direction! Heh heh!

Live gigs and rehearsals are probably out of the question (unless things go seriously viral...Yea' right!), but we might be able to cobble a few MP3 tracks together!

Anybody up for it?

JasonHippy 739 Practically a Master Poster

What are you talking about? The saxophone is a woodwind.

See, I'm that bad with woodwind instruments I don't even know what they are!
Yeah sorry, I forgot about the reeds on 'em. Remember, I'm not infallible, I am only a metal drummer after all!

It was the horrific memory of the saxophones bright, shinyness and its unwillingness to make any kind of noise that vaguely resembled music that was distracting me OK?!

Heh heh, I've been a drummer for a long time now (about 18 years) and it's had a profound long term effect on me! (as is probably evident by the shambolic ramblings in my posts...)

JasonHippy 739 Practically a Master Poster

But I should be kept away from woodwind instruments at all costs!
I've tried flute, clarinet, trumpet and saxophone in the past....

Oops, before anybody says anything, yes I'm aware that trumpet and saxophone aren't woodwind they're brass!

What I should've said was:
I should be kept away from woodwind and brass instruments at all costs!

That'll be the drummer part of me acting up again! :)

JasonHippy 739 Practically a Master Poster

Wow, that was pretty amazing!
Nice find!

JasonHippy 739 Practically a Master Poster

My favourite times of the day are:
Breakfast time, lunch time, dinner time and bed time!
Oh and lets not forget Miller time! heh heh! :D

No but seriously, being a perennial sun-dodger I love the late night/early morning...
From about 3am, after most of the local drunks have finally stumbled home; to 7:30(ish)am, just as the sun's come up and everybody else is getting ready to go to work still drunk or with the beginning of a mighty hangover.
You can't beat seeing a good sunrise before going to bed on weekends!

And my favourite time of the year is the autumn/winter..'cause the night is that bit longer! :)

JasonHippy 739 Practically a Master Poster

Outside of being a computer geek I'm mainly a
* Music Geek
* Martial Arts Geek
* Book Geek
* Food Geek

JasonHippy 739 Practically a Master Poster

Drums and percussion are my main specialities, I play drums for an extreme/technical metal band called Downfall. I also teach drums at our guitarists studio.

I can play guitar and bass to a fairly high standard, plus some rudimentary keyboard/piano.

I've tried a few other stringed instruments over the years (banjo, ukelele and balalaika) and would like to have a go at violin or cello at some point.

But I should be kept away from woodwind instruments at all costs!
I've tried flute, clarinet, trumpet and saxophone in the past, but with disasterous noisical consequences! I just can't get my head 'round 'em...Maybe that's the drummer side of me coming out! heh heh!

JasonHippy 739 Practically a Master Poster

Nice one niek_e!
I was sure there was a better way of doing things...But for the life of me I couldn't think of it!
I've not seen distance before (must've missed it in my std library reference book)...That's another one for me to add to my std lib arsenal...I'll have to remember that one!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I've been listening to rather a lot today...
Clutch (Blast Tyrant) on the drive to work, Tool all morning, a bit of Frederik Thorendals Special Defects (Sol Niger Within) and Naked City (Torture Garden) over lunch... Currently listening to some Meshuggah (Destroy Erase Improve)..but thinking of switching to some Front Line Assembly, Skinny Puppy, Foetus or Venetian Snares for this afternoons slog!

JasonHippy 739 Practically a Master Poster

Personally, I wouldn't miss either of 'em!
The only reason I own a mobile phone is because my wife and my bandmates nagged me into it, so they can pester me incessantly....So if my phone should ever so accidentally on purpose fly off my desk and into the wall...ooops!.....Hey if my wife asks, none of you saw that OK?!

And I don't own an MP3 player. I don't walk around enough to need one! However if my car stereo was to die or get stolen, that would be a completely different matter!
Can't...live...without...music...in..car...aaaaagh!

Heh heh :D

Being a thirtysomething, I guess that makes me a member of the 'Last Generation'

JasonHippy 739 Practically a Master Poster

Damn, I was too late! (probably wrong too! heh heh!)

JasonHippy 739 Practically a Master Poster

I could be wrong, but I don't think that theres a way of getting your max_iter iterator to give away the position of max_element...Unless Torture works heh heh...Bring on the COMFY CHAIR! :D (Apologies for the Monty Python...I couldn't resist!)

Anyway, this is about the only thing I could come up with:
(BTW: I've not compiled or tested this snippet, but you'll get the general idea!)

// ....your headers and code from before your snippet goes here

// here's your snippet:
// your vector
vector<int> v = {1,2,4,6,8}

// you've found max_element
vector<int>::iterator iter_max = max_element(v.begin(), v.end());
cout << "Largest element is " << *iter_max << endl;

// now find the position..hmm how about this?
// iterate through the vector again, but this time we'll count the number of iterations until we reach iter_max
// so we'll use a new iterator and compare it to iter_max
int index=0;
bool isFound=false;
for(vector<int>::iterator iter = v.begin(); iter!=v.end(); ++iter, ++index)
{
	if(iter==iter_max)
	{
		isFound=true
		break;
	}
}

if(isFound)
	cout << "The index of the largest element is: " << index << endl;
else
	cout << "Doh!...Something went wrong!" << endl;

// your code after your snippet goes here.....

OK, it's probably not ideal, but that's the quickest and simplest thing I could think of...Probably OK if you're only using a small vector, but not so good if you've got a large one to iterate through!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Looking at your original post again, if it's just a case of removing the stuff after the decimal point and then adding your commas in the appropriate place, i'd probably do the following:

If you're perfoming your calculations using ordinary floating point arithmetic:
1. perform your calculations
2. convert your results to int (thereby removing the decimal digits)
3. convert to string
4. parse through the string and add commas.

steps 2 & 3 above could be done in one line:

strVal = str(int(calculatedVal))

If you used the Decimal class to perform your calculations, and your results are already in strings then:
1. Perform your calculations
2. Use split, as mentioned by djidjadji (but don't cast the first part to an int keep it as a string!)
3. parse through the resultant string and add your commas.

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

If all you want to do is remove the floating point digits you could do this:

floatValue=3.141
integerValue = int(floatValue)
print "The integer equivalent of", floatValue, "is", integerValue

Note: The above code is python 2.x syntax. For python 3.x change the print statement to:

print("The integer equivalent of", floatValue, "is", integerValue)

All this does is create a new integer based on the value of the floatValue. Anything after the decimal point is discarded in the integerValue.

Alternatively, because python variables can hold any data-type, there's nothing stopping you from doing this:

value=3.141
print "The initial value is:", value
value = int(value)
print "The value is now:", value

Again, if you're using python 3.x, you'll need to alter the print statements.

All the above code segment does is converts the float value into an integer. So initially value holds a float, but line 3 changes it to an int. Again, anything after the decimal point is simply discarded.

Another alternative is rounding using math.floor() or math.ceil().
math.floor will round down to the nearest whole number and math.ceil will round up to the nearest whole number.
Using floor or ceil will allow your values to remain as floats.

import math

value=3.1412
print "Value is:", value
print "math.ceil() rounds value up to: ", math.ceil(value)
print "math.floor() rounds value down to:", math.floor(value)

Again, this was 2.x syntax, alter the print statements if you're using 3.x.

The thing to bear in mind with all of …

JasonHippy 739 Practically a Master Poster

Considering the problem you have set, your algorithm is completely wrong. And as already mentioned by niek_e, you're using the for loop incorrectly too!

Follow niek_e's advice and take a good look at using for loops.
His post shows you how to correctly use them..
And as he's already said, you should change void main to int main or risk Salems wrath ;) heh heh!

Going back to your actual algorithm, what you need to be doing inside main() is something like:
1. initialise your variables, include a boolean flag to check whether the user was correct (initialise it to false).
2. set up your for loop to iterate three times
Inside the loop you need to do this:
- Ask user to enter a value between 1 and 10
- If the entered value matches the password (3?), set your flag to true and break out of the loop
- else if the value is less than one or greater than 10, display an error message.
- else inform the user that they guessed incorrectly..

(finally after the for loop)
3. check the value of your flag.
- if true, the user guessed correctly during the for loop.
- else user guessed incorrectly 3 times and failed!

Hope that's of some help!
Cheers for now,
Jas.

tux4life commented: Nice post :) +22
JasonHippy 739 Practically a Master Poster

In main() you aren't instantiating your matrix class correctly.
Also your add and multiply functions are currently member functions so you'd have to access them via an instance of your Matrix class.

To correctly instantiate your class you need to do something like:

Matrix* mat1 = new Matrix(rows, cols, initValue); // pointer to a new matrix

or perhaps:

Matrix mat1(rows, cols, initValue);

Likewise, you'd have to do something similar to instantiate mat2.

Then there's this bit of code in main, which is what is causing the errors you mentioned:

for(int i=0; i < rows; i++)
		for(int j=0; j < cols; j++)
			Add(mat1, mat2);
	
	for(int i=0; i < rows; i++)
		for(int j=0; j < cols; j++)
			Multiply(mat1, mat2);

As mentioned, the problem here is that you are trying to access a function which is a member of a class, but you don't have a proper instance of the Matrix class...

I'm not going to solve the whole problem here for you, but I can point you in the right direction...
What you really need to be doing is something like this in main:

Matrix* resultOfAddition = mat1->Add(mat2);
Matrix* resultOfMultiplication = mat1->Multiply(mat2);

or:

Matrix* resultOfAddition = mat1.Add(mat2);
Matrix* resultOfMultiplication = mat1.Multiply(mat2);

(depending on how you instantiated your class!)


You then need to change your Add and Multiply functions, so they take a constant reference or a pointer to a Matrix object as a parameter also make them return a …

Salem commented: Much more detailed than my terse effort +36
JasonHippy 739 Practically a Master Poster

Hey Raja, I don't know if you've already solved this but I'd pretty much agree with Iamthwee!

Upping the frame rate of your final movie should minimise jerkiness a little. And it is true, the default flash tweens can be a little buggy at times...Also Tween lite is a very good alternative tweening library...very fast in AS3 too!

Otherwise, if you're only going to be using one or two different tweens in your swf, then you could take a look at Robert Penners website:
http://robertpenner.com/easing/

He's released several tweening algorithms for AS1 and AS2 over the years. They are pretty simple (in the sense that there isn't much code!) and quite fast (especialy when ported to run in the AS3 engine)...Some of the code can be quite hard to understand in places as he's used one letter variable names for a lot of the parameters and calculations in the algorithms...This was because longer variable names incurred a considerable performance hit in AS1/AS2. So to maximise the speed and efficiency of .swf's using his easing algorithms, he used single letter variable names.

If you want to know what the single letter parameters and variables represent, take a look at the free chapter from his book (also downloadable from his site...Click on the "Tweening chapter of my book" link!)

Anyway, take a look at his site, if you like the look of any of his tweens, all you do is download the AS2 versions of …

JasonHippy 739 Practically a Master Poster

36.
You are an average on-line user. You may surf the Web a bit too long at times, but you have control over your usage.

JasonHippy 739 Practically a Master Poster

Oh yeah, cheers Raja!
I completely forgot about wmode!
I've used it once or twice in the past, but obviously not often enough to remember it, it would seem. Nicely spotted!

Jas.

JasonHippy 739 Practically a Master Poster

Ah yes, I should've spotted that howler when I helped you yesterday!

For the last people you ask, their votes are not getting counted..
What you need to do is ask for input before the switch, so perhaps try something like this:

#include <iostream>
using namespace std;

int main()
{
	const int NR_SESSIONS = 3;
	int nrAttend;
	int votesForS, votesForR, votesForO;
	char vote;
    
	// Initialise totals
	votesForS = 0;
	votesForR = 0;
	votesForO = 0;

	// Loop over sessions
	for (int i = 0; i < NR_SESSIONS; i++)
	{
		cout << "SESSION " << i+1 << endl;
		cout << "How may pupils attended this session? " << endl;
		cin >> nrAttend;
		cout << endl;
        
	// Loop over attendants  
	    cout << "Vote 'S' for Scarlett, 'R' for Rhett and 'O' for any other character! " << endl << endl;
		for (int j = 0; j < nrAttend; j++)
		{
			cout << "For whom does pupil " << j+1 << " vote? ";
			cin >> vote;
			cout << endl;
			switch (vote)
			{
			case 'S':
				votesForS++; 
				break;
			case 'R':
				votesForR++; 
				break;
			default:
				votesForO++;
			}
		}
	}

	// Displays results
	cout << endl << endl;
	cout << "Votes for Scarlet:  " << votesForS << endl;
	cout << "Votes for Rhett:  " << votesForR << endl;
	cout << "Votes for Other:  " << votesForO << endl;
    
	return 0;
}

My bad, I should've spotted that yesterday!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I must be some kind of programming junkie or something...I think I've got a problem! :-O

Mainly C/C++, and some Assembly by trade...
But lots of recreational and past vocational use of Python, Actionscript and Java.

Also there's the very occasional guilty bit of .NET/CLR stuff (C++, C# and some VB) from time to time.

I've also used many implementations of Basic over the years. (from BBC, Amstrad, Commodore and Spectrum up to Blitzbasic, VB and VB.NET)...Not much time for basic nowadays though, but occasionally I'll dig out the trusty ol' 464 and bash out a few lines before finally giving in to the temptation to load up one of the old classic game cassettes...I love that loading sound! :*

Did some Pascal and Delphi at college (who didn't?!)..But I didn't inhale! heh heh!
I've also experimented from time to time with older/more obscure stuff like Cobol, Lisp, Fortran and Eiffel.

Then there's all the usual web-based stuff (html, javascript, php, perl), not to mention all of the nasty database stuff (Various SQL-like bits and pieces..yech!)....

Yup, I think I've definitely got a problem..But I guess actually admitting it is the first step!
But saying that...I don't see it as an addiction, more a collection...Well, that's my story and I'm sticking to it! :D

JasonHippy 739 Practically a Master Poster

Hey there,
Attached is a quick example to show you what I mean.
I've attached example.zip which contains a simple 200x50 .swf with an example of that text effect from the tutorial you posted. (example.swf)

The .swf has been exported with a white background, so it should be very similar to what you've currently got.

I've also included a very rough (and very orange) html file (example.html) which I knocked up in a few short minutes to show you what I was talking about in my previous post...There's no nice css or formatting in there or anything I just threw this together really quickly, so apologies if it is ugly to look at!

All it does is embed three instances of example.swf on the page.

The first instance has no bgcolor parameter in the embed tags, so it appears white. The second has had it's bgcolor parameter set to red, and the third is set to orange (so it blends in nicely with the rest of the page!)

Cheers for now,
Jas.

sam023 commented: ur post is really helpful +1