jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Reread Banfa's post as he has given you the answer. Specifying map[1][1] gives you a pointer to the row on line 28 in the code above, so it is of type int * . You need the third dimension in there for "map" to resolve down to an int.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Have the constructor in your serial port class take in a TextBox (and have a private TextBox field to hold the object). When you instantiate your serial port class in Form1, pass in the TextBox from your form.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

An approach, perhaps not the most effective and fanciest, would be to implement a "turn" based system. Make a class for your snake and make a "game" class that contains a snake object. One turn will pass once you've placed all the food, moved all the enemies one or more steps and finally move the snake based on what the user has entered. You'd instantiate the game class in main and use its method "playOneTurn()" or some such to do the 3 steps in the turn (repeat playOneTurn() until the game is over).

Let me know if you need a more concrete example. Others may have another idea or two.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you provide an example of what you are looking for? Are you asking about wrapping up your game code in main in a while or do/while loop so you allow the user to repeat playing?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Firstly, thanks for posting neat, organized, well commented code as that is definitely appreciated around here. It's helpful for you to write out your questions instead of leaving them in the comments, though.

In looking over your program, one error that sticks out (there may be more that I missed) is on line 311. Two problems with it: firstly it is an assignment rather than a comparison operator and the second is that it is difficult to compare any floating point value for equality since your representation of 1.0 in memory could be 1.00001 or 0.99998 which would not be equal to 1.0. Instead, establish the absolute value of (p - 1.0) is less than some preset epsilon (say 0.00002).

See if that change affects your problem on line 216 at all.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The code looks ok to me but textbox4 line 4 doesnt change to "Succes".

I was having some deja vu as I believe I have helped you with this last issue before:
http://www.daniweb.com/forums/thread261339.html
Even though Lines is technically read/write it seems as if you have to write via setting it equal to a "gcnew'd" array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This sounds like a situation that calls for a backgroundworker object http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx. That being said, part of the problem you were having above is that you need to pass in a System::Windows::Forms::Form instead of a Form1.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Something is wrong with your linesuckup.linenum value. Where is that coming from? Check it versus textBox2->Lines->Count .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A richtextbox has a member Lines which is an array of all the lines of text (so Lines[0] would be the first line, etc). So yourRichTextbox->Lines->Length gives you the total number of lines. So you can do something like

for (int i = 0;i<richTextBox1->Lines->Length;i++)
{     
   if(richTextBox1->Lines[i]->Contains("findme"))
	 MessageBox::Show("Found it at line "+(i+1).ToString());
}

Of course that will only find the first instance of it, so if you want something else you'll have to keep track of where it was found, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How do i load a text file to a windows clr textbox?

Using a System::IO::StreamReader object and it's ReadToEnd() method. This will give you a String ^ to which you can set your textBox1.Text.

and how do i save the lines of the textbox to a file?

Use a System::IO;:StreamWriter object. It has methods Write() and WriteLine() that you can use just like the Console::Write() and WriteLine() See how far you get with that and post back if you need more information.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Myself, it seems much more feasible that he would want you to check if it were empty. Then you return -1 and the output of the numbers stops in printQueue. Based on the instructors own driver code returning a -1 stops the output process dead in its tracks, so why should the program not output a full queue? I could be missing something but that seems fishy to me.

I modified the dequeue method to this (in psuedocode so I don't take away your fun)

IF QUEUE IS NOT EMPTY 
{
   ELEMENT = QUEUE[0]
   SHIFT ELEMENTS DOWN
   DECREMENT LENGTH
}
RETURN ELEMENT;

You'll need to do the initialization of element and other housekeeping too
My output:

Queue properties:
 isEmpty = 1
 length = 0
 size = 10
 first element = -1

Queue properties:
 isEmpty = 0
 length = 5
 size = 10
 first element = 10

Queue elements:
 10
 13
 32
 3
 16

Queue properties:
 isEmpty = 1
 length = 0
 size = 10
 first element = -1

Queue elements:
 The queue is empty!

Queue properties:
 isEmpty = 0
 length = 10
 size = 10
 first element = 0

Queue elements:
 0
 10
 20
 30
 40
 50
 60
 70
 80
 90

The extraneous -1 from the listing ending in 16 has also disappeared.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Read over this portion again. Your if statement in the block is not doing any of these steps.

// TODO:
// This method removes and returns the first element
// in the queue. You should first check that the
// queue is empty. Adjust the length of the queue
// after dequeuing the element.
//

How do you check if the queue is empty? Use the isEmpty() method. Only if your queue is empty return -1 so that your printQueue function doesn't print anything.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was asking you to trace through the printQueue so you could see that your dequeue method is in error. There's no need to change the driver. The if condition within the dequeue method will always be true for length the same as size so any queue of length 10 will return a -1 regardless of how many members are in it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Add in a set of braces between line 71 and 72 and between 73 and 74. This isn't tha main problem but your enqueue was happening regardless of the length.

Trace through your portion that prints out the queue in the driver. After the queue is cleared and the 10 elements are added, you have size = 10 and length = 10. Therefore, length+1 >= size and so dequeue returns -1. In your printQueue function this is taken as a signal to break.

Try making the changes around that and post back if something else arises.

BobbieJean commented: Jonsca is always a great help! Awesome poster! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are a couple of problems.
getline in the form that you have it on line 45 (with the filestream as a parameter instead of as the object) takes a std::string for the second parameter. Your second parameter is an int.

You can either read it in as a string and parse it with something like atoi (for example, many options here) or use file>>black.hour; to take it in directly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok. Post back when you've made some inroads.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The changes are not going to be drastic. I would eliminate all the recursive parts as that's probably not what you intended anyway. Just think in terms of, ok, how do I determine if the queue is empty. Check the length and return true if the length is zero. Your instructor has taken the time to delineate the steps for you, so just flesh them out one at a time.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're calling the functions within themselves so it's going to proceed through those calls until the stack space runs out. isEmpty() will call isEmpty() which will call isEmpty()...etc. ad nauseum. You have a variable that keeps track of the number of items on your stack, use that in your method instead.

Same idea with dequeue. EDIT: You do it with enqueue also but the compiler doesn't complain about it because it's in an if statement, but that should certainly be addressed as well. Going back over it it seems like you are having a hard time with the concepts. Sit down and go through your instructors TODOs step by step and plot out on paper what you need to do for each.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a stringstream to create the filenames.

#include <sstream>
stringstream ss;
ss<<filenamestring<<number<<".txt"; //number is the int from your loop index

Then use the .str() method of the stringstream to get the string in conjunction with the .c_str() operator of the string to get the char * that the ofstream method requires.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just leave the size() method where it is, it will be a "close enough" match. If you haven't learned a lot of this stuff yet it might be best to focus your efforts on the other portions before this one.

Skip the lower all titles part and just make the string in your array "book 1" instead of "Book 1". Just run the loop over your title string that the user has just inputted.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On line 7, just scratch out the "size_t=" part and leave the int i and set it equal to zero.

For the allTitles, I would just make the array values in lowercase to begin with. In the above case I would do the transformation on title, writing it back to title: title[i] = toupper(title[i]); As far as the stuff with n goes, I was thinking if you wanted to change the arrays to lowercase programmatically

for loop over i for each of the books
{
    for loop over n for each of the characters
    {
         allTiles[i][n] = tolower(allTitles[i][n]);
     }
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
allTiles[0] is "Book 1"
allTitles[0][0] is 'B'  //which is a char
allTitles[0][1] is 'o'
allTitles[0][5] is '1'

Just like:

mystr = "example"
mystr[0] is 'e'
mystr[5] is 'l'

Step through them in a loop just like you would with an array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

size_t is the type for your index. I was trying to be proper but it probably made it more confusing,apologies. When you ask for the size of a string using that size() method it returns a size_t value (which is usually just an unsigned int). Change it back to int for the time being if you are more comfortable with it that way. string doesn't come into the value of i at all.

Your string in question is any one of the ones stored in allTitles. So use i for your book index and change the index for the string characters to n or something.

I replied on your other thread too. You should probably stick to one or the other since they are similar. If you hit "Flag bad post" on the left under your name you can request that a mod close one or the other.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'll offer the same advice as before. You have your working function now, so get your menu function working independently and add things in one by one, compiling in between.

Line 40 is not going to do anything. Lines 50 and 51 are going to overrun the array bounds. On 79 you don't initialize i. I would rethink your approach on 81 and 82 a bit, since your i-- is a postfix operation.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, you'll have to use array notation to march through the string you take in.

string mystr = "example";
for (size_t i = 0;i<mystr.size();i++) //we need i's type to match the type of mystr.size() 
{    //leaving it as an int will elicit a warning from the compiler in some cases
   mystr[i] = tolower(mystr[i]); //your books are already in an array so just 
                                  //use allTitles[0][i]
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

strangely not book 2

The case of the two strings must match exactly for them to be equal. To remedy this you can convert everything the user enters to lowercase using the functions in #include<cctype> (http://www.cplusplus.com/reference/clibrary/cctype/toupper/ there are many other ways to do it too) and make sure your array strings are all lowercase.

I ran it a couple of times and it seems to do the job but you'll have to test it thoroughly. An "optional" step would be to move your arrays into main() and out of the global space -- it's a good habit to avoid globals.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

the return false is right though isn't it because we are testing the inputted title against all elements in the titles array it seems to be working except that it does not cout the corresponding price if i enter " book 1" it says that the book is found in

Your test cases are betraying the true behavior of your program. Say there are four books book0,book1,book2,book3. If you are looking for book two, if you have the return false where you do now it's going to find book0!=book2 and you'll leave the function. If I were looking for book5 in this scenario I want to go through book0,book1,book2,book3 to make sure it's not the 2nd, 3rd,last book in the chain. It's a simple fix, just return false after the for loop ends and before your function ends.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok, you've made some great improvements in the code. Take a look at this document on formatting http://www.gidnetwork.com/b-38.html, as formatting makes it a lot easier to read and follow and will aid in checking all the braces match.

Your function still needs some work. I've told you that you need to bring getline before the start of your for loop. Trace it out- for each time you go through the for loop (over the number of books in the array) you'd be prompting the user for a new book. Prompt the user for the title _once_. You need to disintegrate your if/else structure and turn it into an if that returns true but no else. I mentioned before that you need to return false only if you've gone through the entire for loop and not struck on the title.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How did you add the resx file? (I couldn't do it in the Express Edition). The resource I added to Form1.resx did persist there after I reopened it.

If you go to access the resources in C# you just use my_resources.resourcename but as we've figured out it's a slightly different animal in C++/CLI.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Array size must be a constant determinable at compile time (yours requires the user to enter numbers at run time). You can dynamically allocate your array with int * array = new int[c]; . Some compilers have extensions to their C compilers to do what you did but the results are not portable and non-standard.

Also, look at line 10. It is not going to give you the intended result. Loop through the elements to display them

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On my post count graph in the profile it lists all the weeks and then it puts an entry for Jan 3rd at the very end. See screenshot below from when I mouse over it. I'm not sure where this is coming from as it doesn't represent any kind of maximum post count or anything. Jan 3rd also doesn't match up to the date corresponding to the week in January that actually shows up on the graph.

Anyway, it hasn't been a bother at all, just a curiosity. I figured I would post it up in case it was a symptom of a bigger problem.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are only taking bits and pieces of what I have been telling you. In this latest version you have not closed main() with a } and kept your function definition, i.e. the

bool myFunction(string arr[],double darr[]) //no semicolon -- these parameters are just an example, use your real ones
{


}

outside of main. If you have a text, look up the use of the braces with loops -- it is critical that they match up, one for one, one { per each }. Also, look at some programs that have functions and note where the prototype and definition are located.

You'll need to fix your arrays as using MAXSIZE is correct in the definition of those arrays in lines 9 and 13 but when you try to access element MAXSIZE, you've overstepped the bounds of the array (since an array of size 4 will have index values of 0 through 3)on lines 33,37,38.

I know you think you've come too far to do this but it will save you an immense amount of time if you start a new project with no code other than the skeleton and fill in the pieces one by one, compiling as you go.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please post the current code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Lines 6-8 are the prototypes and they need the types of the variables e.g., void readThreeNumbers(float number1, float number2, float number3); (in the prototype the names number1,number2, and number3 are optional, not the types).

Since you are passing the float variables into your functions anyway, and because global variables are a bad habit to get into, you should move line 5 inside of main().

Also, you should remove the .h from your header files, the ones with the .h are prestandard.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Refer back to the skeleton code I gave you to place the function definition. Line 32 in the above listing is completely wrong.

Also, your if statement doesn't have a closing brace and if you write else without the braces the statement will encompass the else and the line immediately following it.

if (condition)
  I get executed

Not part of the statement

//versus having

if(condition)
{
   I get executed
   Part of the statement
}
else(condition)
   Part of the else
Executed regardless

I tried to explain this before, but do you want to get the title each time the code goes through the for loop? No, so move line 31 out of there and before the for.

Here's some pseudocode for your loop

READ INPUT FROM USER
FOR (over the books array)
{
  IF WE FOUND THE BOOK, SAY SO and RETURN TRUE

}
  IF WE MADE IT THROUGH THE FOR LOOP, WE HAVEN'T FOUND IT
     RETURN FALSE
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In my head if the book was the third in the list and was a match providing there was 3 books in the array then it would find it


as it is i could check the first 2 elements only initially hence why i was using an i=0 < Maxsize , I++ type function so that if it occured in the array it would check all elements once to see if there is a match logically that is how i see it anyway


If the book is third the list an allTitles search is required in my head to check to the ith or as i=0 the 0 to maxsize number of elements

Looking at the second program as a guide the cin Value firstly has to become a getline but i would imagine that it would check the array once then return true or false

Yes, if it doesn't find on the first try it will return false and the function will be done at that point and it won't continue through the loop.

Here is a basic layout so far producing linker error on the findtitleprice function

Yes, since there is no definition of the function it has nothing to go on.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i thought the return true value in the loop is enough;

It is in the full set of code but in the skeleton the compiler probably complains if there is no return value, so I was suggesting that as a placeholder.

then return true else return false as you hvae to return false if not match is found

Trace your code out for a scenario where the book you are looking for is third on the list. What happens after the first pass through the loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check your "character.h" and see if you have a semicolon after the class declaration (I didn't download your project).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First, start a second file that looks just like the one in my last post. You will probably need to put a return true; at the end of your function definition. Compile the file and make sure everything is ok. Now you can add the pieces back in step by step and compile in between each.

Your for loop could be laid out better. Trace it through by hand on a piece of paper. You want to do something along the lines of 1) get the tile 2) have a for loop step through and see if it finds it (if so display the result) 3) if you've gone through the for loop and haven't found anything, then display that nothing was found. Find a way to tell if you've been through the entire for loop. You could probably use a boolean value as a flag.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://www.windows-tech.info/18/504d408117484041.php for a great reference.

Normally in C# I would add in another .resx file but there doesn't seem to be a way to do that in 2008 or 2010 Express Editions. You can add them to the existing Form1.resx (the IDE will balk at you): open that file up in one of the tabs (it may be hidden under Form1.h in the solution explorer) and go to the add resource. Note the name that VS gives your image for later.

Follow the steps in the link above, except instead of Project1.Form1 substitute <YourNameSpace>.Form1. Skip over the GetStream step and instead do pictureBox1->BackgroundImage = dynamic_cast<Image^>(myres->GetObject("thenameVSgaveyourresource")); Give that a try...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Could you clarify your question with an example of this situation?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's a skeleton for you to follow:

//#includes up here
bool myFunction(string arr[],double darr[]); //the names of the parameters are optional
                                               //in the prototype
int main()
{
    string strarray[300]; //initialize these if you need to
    double dblarray[300];

    bool result;
    result = myFunction(strarray,dblarray); //no types here for parameters or return


} //main ends before the function definition begins

bool myFunction(string arr[],double darr[]) //no semicolon
{


}

Something else to consider (even though you are just starting out) is using a vector. Then you won't have to keep track of the number of elements and the vector will expand in size if you need it to. See http://www.cplusplus.com/reference/stl/vector/vector/

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would try outputting filetodisplay_system_string values via System::Diagnostics::Debug::WriteLine() (they'll end up in the output window)and make sure there's nothing funky there. Unless it's a flukey error there is something wrong with one of the strings that you are passing to that constructor.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to go to Project/YourProject Properties/Settings and add in the defaultFile setting. bbman has it holding the directory name instead so you can skip his line 2 and change his line 5 to Properties.Settings.Default.defaultFile = openFile.FileName; . Now you can use the filename whenever you need it.

You may need to redo some of the code in your routine as stream2.ToString() is only going to give you "System.IO.StreamReader" as a result.

All that being said...

All i really need now is a way to grab the path of the file from StreamReader stream1 = File.OpenText(ofDialog.FileName); or where ever it would be most convenient and pass it back as a string to the variable path. Any help would be appreciated.

If you have ofDialog.FileName just save it as "path" (or using a default setting as above) and then pass "path" to File.OpenText . Just make sure it's getting assigned before it is being used.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I understand. I was asking what code is generating the file name that is used? That method might be giving "bad" strings if you've overstepped your set of filenames.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since not all routes through your if/else structure assign "path" a value (as your dialog result could theoretically be another value and there is not an else clause for that if), path go unassigned and have no value. In addition, the compiler is complaining that if your clickcounter is odd you'll have an empty value for path on line 44.

Some rearrangement of the structure is necessary as initializing the value will only serve to keep the compiler at bay and cause more problems later.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is generating

<filetodisplay system string>

?

the only thing i can think of that is causing the error is recursivity

Is there a proper base case for it? (I would think this would generate some kind of stack problem instead of the invalid parameter, though)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Create a private int within your Form1 class (or could be public, if you needed that) and increment it in your button_Click method.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How does what you wrote relate to your original problem?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This thread has a bunch of different suggestions: http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/40ed753e-47af-4638-8a72-1d607102a05c I've never run into that problem personally, though.