Murtan 317 Practically a Master Poster

If the compiler is complaining, the code is obviously still not right.

Maybe you should define the missing symbols?

try int array_words[10]; right next to where you declare get_content. (They're both used in the same place.)

The declaration for char str[BUFSIZ] needs to come before the for loop that copies into it:

for(int i =0; line[i];++i)
    str[i]=line[i];

That code sure looks like a strcpy() to me, maybe you should look into it.

PS- When posting c++ code, please use c++ code tags
[code=c++] // Your code here

[/code]

Murtan 317 Practically a Master Poster

If you want to use a recursive algorithm, I think you will have to pre-define the entire output area as a grid to allow the left and right sides random access to the output space. Then when the recursion calls are complete, you output the grid.

To be able to 'output as you go' you will need to use a non-recursive algorithm as you need to traverse the tree by depth.

In either case, the width of the output will be determined by the depth of the tree and the output size of the elements in the tree. (One character or more?)

Once you determine the width, the root node is 'centered' on the width.
Then at each lower level, the new 'top' node is 'centered' on its half of the previous width.

With single character outputs, a 1 depth (root only) tree is 1 wide, a 2 depth tree is 5 wide, a 3 depth tree is 11 wide and a 4 depth tree is 23 wide.

So in the output tree, there are 11 spaces in front of the H
Split 23 into 2 halves of 11 each and there are 5 spaces in front of the D. Split 11 into 2 halves of 5 each and there are 2 spaces in front of the B.

Thoughts on a recursive implementation:

A 4 depth tree, needs 23 width and 7 rows.

We could declare a 2 dimensional array: …

Murtan 317 Practically a Master Poster

I thought we were trying to hint you toward a ShowPage(int pageno) type of implementation.

Then inside ShowPage, you could determine the start and end indexes for the page. (I'm presuming here that pageno starts at zero.)

int startidx = pageno * 15;
int endidx = min(startidx + 15, sldNum);
// sldNum is the member that has the maximum slide number, right?
for (ii = startidx; ii < endix; ii++)
{
    // size and position the control sldArray[ii]
    // I might have written the code differently, but your code should work.
}
btnNext.Enabled = endidx < sldNum;
btnPrev.Enabled = startidx > 0;
Murtan 317 Practically a Master Poster

You have to distinguish between the pointers and the data that they point to.

The mystrcpy works by changing its copy of the pointers, updating what the pointers point to.

When you call mystrcpy(s, d) s will not change as it is not a reference, and d will not change as it is also not a reference, but the contets of where d points (to the bufffer in main) IS updated from the input string.

In pad right, if you made a call like the following: void padRight(char const * src, int minwidth, char * dest) where minwidth is the minimum desired width and dest is a pointer to memory large enough to hold the greater of strlen(src) + 1 and minwidth + 1.

Then you would ALWAYS copy to dest and if strlen(src) was < minwidth, you would append spaces to dest until strlen(dest) >= minwidth.

If you wanted to be even safer, you could use a call like: void padRight(char const * src, int minwidth, char * dest, size_t destsize) and then your code could validate that dest (destsize) is large enough to hold the padded string.

Murtan 317 Practically a Master Poster

You'll have to free the memory back in main when you're done with it.

I would almost prefer that you pass an output buffer to the padRight function that is guaranteed to have enough space for the padded string. That would allow you to use either a buffer from the stack (that does not need to be allocated / deallocated) or a buffer from the heap (with new / delete) at the discretion of the calling code. It would then be the responsibility of the calling code to manage the allocation.

In your current implementation, you only allocate if the string needs padding, so sometimes 'a' will point to allocated memory and sometimes it will not. That makes management of the allocation much harder. The calling function must be aware of the internal implementation of padRight, generally not a good design.

Murtan 317 Practically a Master Poster

So what are the 'given' parameters for the tree?

Are all values in the tree guaranteed to be single digits?

Is there a maximum depth limit?

Ok, let me work this out 'on paper' so I understand it:

{Note that spaces are preserved inside code tags.}

Tree with 3 nodes, one L and one R from the root:

B
 / \
A    C

Seems easy enough...

Lets expand the tree by another complete row:

D
   / \
  B   F
 / \ / \
A   C   G

Oops...There is supposed to be a C and an E where the C is...

How do I re-format this to make room for it? Does this work?

D
    / \
  B     F
 / \   / \
A   C E   G

or do I need to add the extra vertical line to keep the lines pretty?

D
    / \
   /   \
  B     F
 / \   / \
A   C E   G

Lets expand it another row:

H 
          / \
     D           L
    / \         / \
  B     F     J     N
 / \   / \   / \   / \
A   C E   G I   K M   O

That looks pretty strange, but maybe we could live with it as it only has one row of 'lines' for every row of data.

If you have to add the extra rows to make the lines pretty, you end up with more rows to get the horizontal …

Murtan 317 Practically a Master Poster

Did you attempt to walk through what your code does in your head?

Here's your code with my comments included:

// Assign a to temp
char *temp = a;
// temp and a both point to the original buffer

// Assign a to point to a new buffer n characters long
a = (char *)malloc(n);
// a points to the new buffer
// ? did you allocate space for the '\0' at the end of the string?

// Initialize the new space pointed to by a to all spaces
memset(a,' ',n);
// a points to the new buffer of spaces

// This one line does a bunch...
// each iteration copies one character from the original string to the new buffer
// both pointers are advanced  to point to the next character
// The loop continues until the '\0' is copied
while (*a++ = *temp++);
//cout << a << endl;

// Now the loop is done:
// temp points to one character beyond the '\0' in the original buffer
// a points to one character beyond the '\0' in the new buffer

// as a is a reference parameter, the pointer back in the main loop also points one beyond the '\0' in the new buffer.

Does that help with 1 & 2?

Murtan 317 Practically a Master Poster

You haven't done enough yourself yet for us to provide constructive help without just doing the work for you. (We don't do that here, we help you fill in the gaps where you lack knowledge, but you have to narrow the gaps.)

The assignment recommended constructors and destructors, declare them and write them. Write the Compute_Bill() method.

Add constructors, destructors and Compute_Bill() to the derived class.

Write some form of main that will create at least one of each, calling their Compute_Bill() and output the bill (or the cost or whatever Compute_Bill() does).

Get the above code to compile and run. Then build on what you have to do the rest of what the assignment asks for.

If you start working and find a compile error that you don't understand, or if you're running the program and don't understand the results (or there aren't any) those make great questions to ask here. Things like "I'm trying to do ___ but when I compile it I get the error ___" or "I expected to see ___ but I'm seeing ___" make questions that are easy to answer for most of the experienced people here.

If you ask properly focused questions, you'll find the answers here are both quick and useful. If you ask broad, open-ended questions you tend to get few if any answers.

PS- when you do post code, please use the appropriate language specific code tags:
[code=c++] // your code goes …

Murtan 317 Practically a Master Poster

Yes, your understanding was correct, the function was changing its 'copy' of the pointer and not the actual start address. (Changing the actual start address is probably a bad idea anyway.)

Your new trimleft would work as written.

A few things to think about:

This first might actually slow the code down a little, but I hate going past a corner and then backing up to turn:

// replace
while (*p++ == ' ');
*p--;
// with 
while (*p == ' ') 
    ++p;

Note that you could also use isspace(*p) if you #include <ctype.h> The second is a minor simplification:

// replace
memmove((void *)a,(void *)p,len);
*(a+len) = '\0';
// with
memmove((void *)a,(void *)p,len + 1);

The +1 makes memmove move the '\0' too.

Third, I'm pretty sure the (void *) casts are not needed, pointers will generally convert themselves to void * without help. (Getting back does require help.)

memmove(a, p, len + 1);

PS- When posting code in a source language, please use the appropriate language specific code tag:

For C++:
[code=c++] // your code here

[/code]

For C:
[code=c] /* your code here */

[/code]

Murtan 317 Practically a Master Poster

Well, if you're not afraid of pointers...

int bin2dec(char * bin)
{
    int n;
    int sum = 0;
    while (*bin) 
    {
        n = *bin - '0';
        if (n < 0 || n > 1)
        {
            printf("\nInvalid binary character: '%c'\n", *bin);
            puts("Binary only uses the digits 0 and 1.\n");
            return 0;
        }
        // double what we had before and add a new low bit
        sum = (sum << 1) + n;
        ++bin;
    }
    return sum;
}

I'm really hoping this wasn't homework, you might be hard-pressed to explain where the idea came from :)

Murtan 317 Practically a Master Poster

If the page starts with n+15, then page 1 starts with 16, page 2 with 17, page 3 with 18?

Doesn't seem quite right somehow.

Do we want to number the pages from 0 like we did the pictures, or do we want to number them from 1 like the user might expect?

Then it would appear that addition is not the correct mathematical operation to apply.

Murtan 317 Practically a Master Poster

I think you're going to have to use all of the 'nature' values and then scale from the nature values to your -1 to 1 grid.

If the farthest the planet gets from the sun is 152,000,000 km then you might scale to 160,000,000 km = 1.

You could continue to do all of the calculations in nature values and only scale to plot, or you could use the nature values once and scale the distance, speed and acceleration (forces).

Murtan 317 Practically a Master Poster

If it is ever circular, other than tail to head, you have a broken list, there will be nodes you can't get to.

The only test I come up with is to run through the list looking for an end or run through looking for a 'duplicate' node.

The first case could be fairly simple if you know how many items should be on the list (or a maximum number of items that could be on the list). Traverse either the known count or the maximum count looking for an end, if you don't find one, you're probably looping.

For the second case, you need a way to 'record' all the nodes you have seen before and as you traverse to a 'new' node, you make sure that it is not on the list of nodes you have recorded. If you have seen it before, you have an improperly circular list.

Murtan 317 Practically a Master Poster

Whether or not the text of the PDF is 'available' is an option for the PDF publisher. I remember several tech documents that were designed intentionally to not allow you to copy the text out of them.

It sounds as if your target document might fall into that category. You could check by using a 'normal' browser to save the file to disk. Then open the file with an 'official' reader and check the properties.

(This would also give you a pdf on disk that you could practice the pdf part of your code with.)

Murtan 317 Practically a Master Poster

Let me ask this a slightly different way to see if it helps you think about it.

You have 200 pictures, numbered 0 to 199. (I chose those numbers because that matches the index in almost all collection data types.)

I propose your screen has a layout something like this:

A   B   C   D   E
   F   G   H   I   J
   K   L   M   N   O
<prev            next>

What picture numbers are on the first page?

What pictures are on the second page?

(If you see a pattern, skip down to the 'N' question, if not fill in a couple more pages and look for the pattern.)

What pictures are on the third page?

What pictures are on the fourth page?

What is the first picture on page 'N'?

So if we had a collection of filenames (or images if you want to try and pre-load them all) and the above formula, we could write a function displayPage(N) to display that page of images from the collection. The display function would enable (or show) the Previous button for all pages except the first and enable (or show) the Next button for all pages except the last. The handler for the buttons would either reduce or increase the page number. (Remember the last page will require a little special handling, as it is likely to not have a full set of images to display.)

Murtan 317 Practically a Master Poster

Not much on the effort part there...

The algorithm will be something like:

  • Start at the head node
  • While there is a next node
  • If the next node is the head node, the list is circular
  • If we got to the end because there was no next node, the list is not
Murtan 317 Practically a Master Poster

That's what the comprehensions were for:

group1 = [listMain[x] for x in [0,4,9]]
Murtan 317 Practically a Master Poster

I'm not quite sure what you're trying to ask for, but did you know you can take a slice of a list?

For example, this produces almost the same output as what you had before.

list=['one','two','three','four','five','six']

group1 = list[0:2]
group2 = list[2:4]
group3 = list[4:]

print (group1,group2,group3)

Another fun thing to play with are list comprehensions:
(The comments are the result from the previous line)

[list[x] for x in [1,3,5]]
#['two', 'four', 'six']

[list[x] for x in range(0,len(list),2)]
#['one', 'three', 'five']

[list[x] for x in range(1,len(list),2)]
#['two', 'four', 'six']

[list[x] for x in [1,3,4]]
#['two', 'four', 'five']

Is any of that useful?
(If not, try to explain more what you're looking for.)

Murtan 317 Practically a Master Poster

It would appear (from the code and our following discussion) that you want to randomly select a character from one of the two lists.

Lets go just a bit higher level, one list appears to be letters and the other appears to be digits.

Are you looking for a 'two-level' selection where we first select letters or digits and then select one of those?

Or would a 'one-level' select one from the set of letters and digits be sufficient?

For the first you could do something like:

char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char digit[] = "0123456789";

char generated;
if (rand() % 2 == 0)
    generated = alpha[rand() % strlen(alpha)];
else
    generated = digit[rand() % strlen(digit)];

The second would be similar, but only use one rand() call:

char genset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char generated = genset[rand() % strlen(genset)];

Is that useful at all to what you're trying to do?

Murtan 317 Practically a Master Poster

All of the comments I've found (with my Google search that you should have made) indicate that application level programs under 32-bit windows (aka Win32) cannot directly access the I/O ports.

The primary suggestion appears to be that if you really need that level of access to the hardware you will need to write a driver to support it. There was also a mention of some sample code included in the Windows DDK.

I have no personal experience in that area, good luck.

Murtan 317 Practically a Master Poster

Coming from python are we?

In C++, the quotes (") and (') are NOT interchangable.

The following lines in your code:

choose[0] = 'alpha';
        choose[1] = 'list';

Generated the following warning in my compiler:

rand.cpp(27) : error C2015: too many characters in constant
rand.cpp(27) : error C2593: 'operator =' is ambiguous

When I changed those lines to use (")

The compiler complained about cout << choose[random];

rand.cpp(29) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

so I changed it to cout << choose[random].c_str() This is the output from my sample run:

alphaPress any key to continue . . .
listPress any key to continue . . .
alphaPress any key to continue . . .
listPress any key to continue . . .
listPress any key to continue . . .
alphaPress any key to continue . . .
listPress any key to continue . . .
listPress any key to continue . . . ^C

(I don't like infinite loops, it would have been nice for you to have an actual exit condition.)

Murtan 317 Practically a Master Poster

From your code, when you call sort(name) :

if 'pile1'in ans:
	sort(pile1)
if 'pile2'in ans:
	sort(pile2)
if 'pile3'in ans:
	sort(pile3)

You pass in one of the lists, pile1, pile2 or pile3.

Then inside sort, you are comparing what you were passed with the strings 'pile1', 'pile2' or 'pile3'.

def sort(name):
    if name=='pile1':
        listMain=mod.passing(pile2,pile1,pile3)
        print(listMain)
    if name=='pile2':
        mod.passing(pile1,pile2,pile3)
    if name=='pile3':
        mod.passing(pile2,pile3,pile1)

In your code as written, none of the tests will ever be true. If you changed those tests to be like the tests in mod.passing (why you have mod still isn't really clear) should work (even though they are entirely un-necesary).

In mod.passing, you compare the argument with the value, not with a string:

def passing(t,m,b):
    if m==pile1:
        listMod1=mod2.calc(pile2,m,pile3)
        return listMod1
    if m==pile2:
        mod2.calc=(pile1,m,pile3)
    if m==pile3:
        mod2.calc=(pile2,m,pile1)

The reason I said the tests were un-necessary is that you could replace all of the code in passing(t,m,b) with:

def passing(t,m,b):
    return mod2.calc(t,m,b)

(I don't see any purpose for mod2 either unless calling between mods is the purpose.)

You could actually simplify the whole bit by changing sort to take 3 parameters as well and making the decision as to what order to pass the 3 in from your main code:

def sort(t,m,b):
    return mod.passing(t,m,b)
# then down in your main code:
if 'pile1'in ans:
    sort(pile2, pile1, pile3)
if 'pile2'in ans:
    sort(pile1, pile2, pile3)
if 'pile3'in ans:
    sort(pile2, pile3, pile1)

But none of that code ever does anything with the return value, so to …

Murtan 317 Practically a Master Poster

The only place in your code where you attempt to print listMain is from inside sort, if the name passed to sort is 'pile1', right?

When do you ever pass the name 'pile1' to sort?

(You pass the list that is named pile1 to sort, but it is not equal to 'pile1' it is equal to whatever is currently in the list pile1.)

PS- When posting python code, please use the python language code tags:
[code=Python] # Your code here

[/code]

Murtan 317 Practically a Master Poster

I think your only option is to change the color of the characters.

Take a look at this snippet

If you set your 'default' color to grey or light grey, white characters will appear 'brighter'.

ddanbe commented: Nice suggestion! +4
Murtan 317 Practically a Master Poster

So 'list' is an index into the virtual heap, and each entry in the virtual heap is a structure that has an elem (the value at that node) and a next (the index in the virtual heap for the entry with the next higher elem).

When there are no entries in the list, the list * l passed to this function will point to -1 (indicating end of list).

So when you add 5, 2, 1 we should end up with:

l = 2
vh->h[0].elem = 5       vh->h[0].next = -1
vh->h[1].elem = 2       vh->h[1].next = 0
vh->h[2].elem = 1       vh->h[2].next = 1

When you add 5, 3, 6 you should get:

l=1
vh->h[0].elem = 5       vh->h[0].next = 2
vh->h[1].elem = 3       vh->h[1].next = 0
vh->h[2].elem = 6       vh->h[2].next = -1

But you appear to be getting:

l=2
vh->h[0].elem = 5       vh->h[0].next = ?
vh->h[1].elem = 3       vh->h[1].next = ?
vh->h[2].elem = 6       vh->h[2].next = -1

The next debugging step would normally be to add some code to dump the entire virtual heap just to confirm what you have is what you think you have. However, I think I see your problem. int * p starts out pointing to the passed in value list * l .

The for loop on line 10 is supposed to 'walk through' the list until it finds where the new value is supposed to go, then it is supposed to update the next value of the record that should …

Whilliam commented: smart post. +1
Murtan 317 Practically a Master Poster

It is a run-time syntax error, aren't you running your program to see how it works?

Murtan 317 Practically a Master Poster

You could do something like this with regular expressions:

if ($stringToSearch =~ /string_id\((.*?)\)/) {
    print "Found $1\n"
}
Murtan 317 Practically a Master Poster

@daviddoria

Umm...what do you think external programs are written in? (ok so maybe they're not c++, but someone had to write them in something).

If you want to write c++ to do file transfers, it is certainly possible. This appears to be the original poster's goal.

Your comment seems somewhat less than helpful.

Murtan 317 Practically a Master Poster

I guess I need to be more specific... if 'q' in exit: is NOT a valid syntax.

I get:

Traceback (most recent call last):
File "path_to_your_file.py", line 108, in <module>
if 'q' in exit:
TypeError: argument of type 'Quitter' is not iterable

(The line numbers between your copy and mine may not match as I had to change the instructions)

Murtan 317 Practically a Master Poster

I believe your 'switch' back to the editor may be related to the clear() function you are using to clear the screen. It requires a task switch to function, and the task may not be switching back as you like.

What is this code supposed to be doing?

if c == 'q':
            gb= raw_input("Press Enter (q to quit): ").lower()
            if 'q' in exit:
             break

Specifically, what is if 'q' in exit supposed to be testing?

PS- my python didn't like your instructions, it was complaining about the 'word style' quotes with no encoding specified. I had to change them to get your code to run.

Murtan 317 Practically a Master Poster

store them anywhere

Who gets to pick where they are stored?

Ok, post the code for what you already know how to do.

Remember to use C code tags:
[code=C] /* your code here */

[/code]

Murtan 317 Practically a Master Poster

@nitu_thakkar

That appears to be a sort for the characters in a string, to put the highest character in the string as the first character.

@taichou

The above sort could be adapted to sort strings in a list.

Where do the words come from?

How do we know how many there are (or will be)?

Once we get them in dictionary order, do we just output the list?

Murtan 317 Practically a Master Poster

We are not, nor have we ever been a 'here is your completed assignment because you asked for it' source of information. Our basic premise is to help you fill the 'gaps' in your knowledge. We help you to solve your own problems. Post some code for how you think it should work, identify where you're having trouble and we will pitch in with suggestions.

Salem commented: Well said!!! +26
Murtan 317 Practically a Master Poster

Ah, but the goal is for THEM to write it :icon_smile:

Murtan 317 Practically a Master Poster

If you changed inputs("Enter name: ", info->name, 30); to inputs("Enter name (leave blank to quit): ", info->name, 30); the way to quit would be clear.

(Did you really need my advice for that?)

Murtan 317 Practically a Master Poster

I would have sworn I saw starting code almost identical to this a few weeks ago.

Did you search for prior solutions?
Did any of them have the same problems?
Have you applied any of the advice in those threads?

Generally speaking, we would prefer you to post your code into your message rather than attaching it unless it is very large.

If you do post code, remember to use python code tags:
[code=Python] # your code here

[/code]

Inside your if c == 'H': you have logic to deal the computer cards. The computer should get no cards until the player selectets 's' to stand.

(PS- c will never be 'H', you forced all input to lower case)

Inside the elif c == 's': you need to have the code for the computer to take one or more cards until his hand is 17 or more.

It might be a good idea to break some of the code out to where you have a funtion to run a complete hand. It could:

  1. deal
  2. show cards
  3. prompt for user input
  4. perform user action
  5. if not 'stay' return to step 2
  6. perform computer action
  7. compare hands and determine winner

Then from the main loop, you just do:

  1. Prompt for instructions
  2. Display instructions if selected
  3. play a hand
  4. prompt for play again
  5. return to 3 if they want to play again
  6. print farewell message (i.e., "Thanks for playing")
Murtan 317 Practically a Master Poster

I'll try and look at it anyway, but if you have an error, why don't you include where the error came from (almost all compilers will give you a line number).

Also, when posting C code, please use C code tags [code=c]/* code here */ [/code] like this:

/* code here */

to get line numbers and syntax highlighting.

Your code has:

void load(void), list(void);
void insertend(void), void modify(void);

It should be: (You're declaring functions, not variables)

void load(void);
void list(void);
void insertend(void);
void modify(void);

Your posted code did not define void insertend(void) or void modify(void) If you're not prepared to implement them now, declare them as stubs:

void insertend(void)
{
}

void modify(void)
{
}

Your menu has two options 6's:

printf("6. Load the file\n");
  printf("6. Quit\n");

maybe one should be 7?

When I ran the program, it stopped taking names when I entered a blank name. It then re-displayed the menu.

Murtan 317 Practically a Master Poster

Show us the code where you create a RuleSet and then where you add a Rule to the RuleSet. RuleSet * Genome declares a pointer to a RuleSet but never actually creates one.

If you don't add any code and then call Genome->AddRule(...) Genome is an undefined pointer (probably NULL) and will fault in the manner described.

Did you mean somewhere to do Genome = new RuleSet(); or would you just prefer to declare it: RuleSet Genome; .

Murtan 317 Practically a Master Poster

On most operating systems, you should be able to setup a 'local' ftp server to test the functionality. If you have a local network with at least one other computer, maybe you could setup an FTP server there.

I am not presently aware of any computers 'in the wild' that will just let you upload. Most systems require authentication (to make sure that you are authorized to upload). In several cases, the permission to upload is related to a subscription of some kind.

Murtan 317 Practically a Master Poster

You're still using data = infile.read() so all of the data is in one big blob. Choice wants to pick one of something, so it picks one of the blob.

Change to data = infile.readlines() so you have an array of words and choice will pick one word.

(For debugging this type of application, I usually add an extra print to show me the word it picked and remove it when I'm done testing.)

Murtan 317 Practically a Master Poster

To do more with the color, you're probably going to want to look at the component parts of the tuple.

For example, the following would count any pixel with more green than red and more green than blue:

for pixel in list(img_I):
    red, green, blue = pixel
    if green > red and green > blue:
        green_I += 1

This counts pixels with any green:

for pixel in list(img_I):
    red, green, blue = pixel
    if green > 0:
        green_I += 1

Some of the 'problem' values for the first case:

  • 254,255,254 - Almost pure white
  • 254,255,0 - Almost pure yellow

Some of the 'problem' values for the second case:

  • 0,1,255 - Almost pure blue
  • 255,1,255 - Almost pure purple

If you wanted to get pixels that were 'mostly' green, I would probably use something like the first case, but make sure the color parts are more than just 1 apart. How far apart would be part of the definition of 'mostly'. And if you want to make sure it was more of a 'pure' green than say a yellow-green or blue-green, you might want to include something about the ratio of blue to red. (In a 'true' green, there are equal parts of red and blue.)

Murtan 317 Practically a Master Poster

@zhelih

Your english is barely readable, and the above post was your first post in this thread, what was your second point?

@asharrajpoot

I had an idea for another way to code the output. What if you built a string that contained the proper first line. (I'll build it manually, but you should probably use a loop.)

char masterline[80] = "A B C D E F G F E D C B A";

Then to print the table as you wanted:

Then you could walk through the row, outputting characters. If the character in the string is less than a limit (we will cover the limit ina second) you output the character, otherwise you output a space.

For the 1st row, print all characters <= 'G' (which would be all of them)
For the 2nd row, print all characters <='F' (all but the G)
For the 3rd row, print all characters <= 'E'
...
For the last row, print all characters <= 'A'

Would that be any easier?

The proposed algorithm would probably consume more CPU than what you're doing now, but I also suspect that both will run so fast you won't notice.

Murtan 317 Practically a Master Poster

From my first glance at your problem, it would appear that the first line is a 'special case' as it does not have spaces at all (which would work as the zero spaces case) but the 'left side' and the 'right side' are not mirror images of each other. Someone has to get the G printed.

What about breaking it down into left / G / right for the first line and then left / spaces / right for the remaining lines.

The reason all of your right sections start with G is because you told them to here: for(sp=71;sp>end;sp--) maybe the 71 should be 71 - row or something?

The reason the right sections don't all go down to A (like you say they should) is because you're incrementing end inside the loop on line 25. If the right sections should always go to A don't change end.

Murtan 317 Practically a Master Poster

The algorithm as posted only counts pixels that are green and only green. There is no provision for counting something that is 'almost' green.

The (0,255,0) represents the color...that's 0 parts red, 255 parts green, 0 parts blue.

The color (0,255,1) while visually VERY close, is not the 'pure' green and would not be counted.

Could this be your problem?

Murtan 317 Practically a Master Poster

I've never worked with Scheme, or Haskell so I can't readily debate their merits.

From what you posted that you know (VB and Assembly) I would recommend that you learn an object oriented language. The goal of working in the language is actually not-so-much to learn the language, even though that will be useful, but to learn to think objects as that skill will apply to any other OO language you might pursue. Python, Java, C++ and C# would all qualify as target languages in that regard.

@Rashakil

Have you ever used Scheme or Haskell in a commercial application, or have you used them primarily in an educational setting?

Murtan 317 Practically a Master Poster

That's pretty easy to derive from the above example, why don't you try what you think should work.

If you try something and it doesn't work, post what you tried here along with the observed results and we'll help you work on it.

if you post more code, please use c++ code tags [code=c++] [/code] around your code.

Murtan 317 Practically a Master Poster

This code array[ child + 1 ] < array[ child ] from percolateDown uses operator < to make the comparison. So your objects need to implement opertor <.

In your case, you wanted to compare the 'val'

bool operator <(struct a const & x, struct a const & y)
{
    return x.val < y.val;
}

This works ok for structs as their members are all public (well, by default anyway). If the data items 'val' were not publically accessable, you could either declare the operator as part of the struct (not usually necessary) or use an accessor. (i.e. getVal())

Murtan 317 Practically a Master Poster

You will have to declare an array of characters to input into, you can't input directly into the enum.

The % format for an array of characters is %s

Then you will have to compare what they typed against a list of strings you have to 'look up' the proper enum.

What do you want to do if the user enters a string that doesn't match any of the days?

(What day is it? Orange)

Murtan 317 Practically a Master Poster

If the word file is one word per line:

infile = open('wordlist','r')
wordlist = infile.readlines()
infile.close()

You do need to strip() the lines, but I would defer it. You could just strip the word you select, and I like random.choice() to pick one from a list.

selectedword = random.choice(wordlist).strip()

I like mn_kthompson's first example for the dashes as it is more flexible for what you want to do. Here it is, slightly modified to build an output string (ostr) and to print the letter or a dash based on whether or not the letter has been guessed.

ostr = ""
for letter in selectedword:
    if letter in guessedletters:
        ostr += letter + ' '
    else:
        ostr += '- '
print ostr

Or alternatively, put the 'extra' spaces in when you print:

ostr = ""
for letter in selectedword:
    if letter in guessedletters:
        ostr += letter
    else:
        ostr += '-'
print ' '.join(ostr)
Murtan 317 Practically a Master Poster

Ok so lets 'draw' one by hand and then figure out how to get the computer to do what we did.

(I'm going to use '.' instead of ' ' so you can see them.)

Ok so in my head, I start with the base of the triange as that determines how big it will be:

*.*.*.*

Then I just add the lines above it:

...*
..*.*
.*.*.*
*.*.*.*

Is that what you wanted?

So, for a 4 row triangle, the first row must be indented 3 spaces, the next 2 spaces, the next 1 space and the last line isn't indented at all.

The first line has 1 star, the second 2 stars seperated by a space, the third 3 stars with spaces and the last 4 stars with spaces.

Do you see a pattern here that you might be able to exploit?