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

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

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

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

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

When declaring an array, the length must be a constant known at compile time. What you are using here is a language extension for C compilers that allows a "variable-length" array to be defined statically. The downside is that your solution will be non-portable and non-standard as not all compilers support this extension. See http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html for example.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use a stringstream(http://www.cplusplus.com/reference/iostream/stringstream/). Remember to call mystringstream.str(""); at the beginning of your loop to clear it out (otherwise all the filenames will get stuck together as you go). Also, remember that ofstream takes a const char* for the filename so you need to use the .c_str() method of your resulting string (so your resultant string would be accessed as mystringstrim.str().c_str() .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Grid_pos[2][2] is a single char but you told Print_Grid to expect an array with second dimension 2. If you want to print the whole grid make the function definition void Print_Grid(int i, int b, char Grid_pos[][3]) and pass in Print_Grid(i,b,Grid_pos); so that you get a pointer to the array. Really i and b are not being used in the function body anyway so you don't need them.

perroned commented: very helpful +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I have edited the above post a bit (just so you get the new changes)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your distance is not being shown on the screen because you don't include it in the cout statment.

An extra newline character in your text file is the culprit. Put the cursor at the end of the last line and hit delete (not backspace). I had thought that it was !infile.eof() that was causing the repeat. However, using .eof() is still a bad idea (see this http://www.daniweb.com/forums/post155265-18.html -- RIP Dave). Use the first getline statement to "drive" the loop.

while(getline(infile,station1,',')
{
   getline(infile,station2,',')
   getline(infile,distance);
   //etc.
}

Also, you haven't converted your distance into the float variable, it is still a string.

kvprajapati commented: Catch sight of! +9
iamthwee commented: *nods* +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I am not sure if that made any sense..

Not really, unfortunately. Give us a few of the categories you could place it into and then we might have a better idea.

It sounds like a Morse code program.

Not a bad response. Judges?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In your function, pass in the 2 chars. Convert them to ints (via subtracting '0') take the sum of the int values and use Convert::ToChar (or really I think you can do a C style cast there) and return that char. It worked for me when I made up a little function to test the other code snippet. I imagine you'll have to modify your method to pass back carry information also.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Rearrange it like this:

array<char> ^ sum = gcnew array<char>(text1->Length); 
//you may have missed the ^ above

//in the loop
{
  sum[i] = a; 
}
/////
String ^ textout;
for(int i = 0;i<text1->Length;i++)
    textout += sum[i]+ " ";
TxtSum->Text = textout;

When not specified the ToString() method of classes simply returns the datatype. You just needed to output things the old fashioned way (if there's a way to do it all in one fell swoop I don't know it).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's because you are using an unsigned int. When the unsigned value is decremented by 1 beyond zero it goes to the maximum value of the unsigned int (see http://en.wikipedia.org/wiki/Signed_number_representations). Using regular ints it works just find since after 0 is -1.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change i=0 on line 37 to i>=0 (i=0 resolves to false so your loop condition is false and the for loop is skipped)

Also, what's the index of the last element of your string ( reverse1.size() would go one past the end)?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, I had been encouraging the OP towards that idea. He hasn't really done any OOP in C# (or perhaps at all). Now we've lost him to PHP...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thanks!

Yeah,ArrayList was a .NET 2.0 thing. I've never dissected them but I believe the List is better designed behind the scenes. I don't know if there's any speed improvement.

Take your time with it. The C++ that comes with the CLR bits is different from standard C++. All the ref classes, handles (^), etc. are particular to the C++/CLI dialect. Just something to bear in mind while you are learning this. If you decide to branch into C# eventually you'll find this to be a hair closer to C# than standard c++ (in that C# and C++/CLI both use the .NET libraries). Just my 0.02.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Because of how the ArrayList stores objects (as objects of type Object ^) you need to cast your ArrayList member before it will give up it's public properties and methods.

ReturnString = (static_cast<PulldownArray^>(PulldownTABLE[0]))->Description;
	
//Consider the List instead, no need to cast
List<PulldownArray^> ^ pdtl = gcnew List<PulldownArray^>();
String ^ returnstring2 = pdtl[1]->Description;

The List is in System::Collections::Generic but if you are using an older .NET you may be stuck with ArrayList

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You set countdown = 5 and when it hits the for loop, the condition is already false (5<5) so it skips the loop completely.

EDIT: Beaten by a hair ^^^^^^^

P.S. Kicking up the warning level on your compiler (so using a -Wall switch with g++ or a /W4 with VC++) would have let you know this

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

One question that has been partially in my way while I make this console app; can I link to external classes?

Yes, you certainly can. If you make it part of your project in the same namespace it's even more straightforward, as you just need to make an instance of the class.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

<Delete>
Sorry I was looking at the dimensions of the wrong array.

Discussion seems to be continuing at the OP's other thread on this.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So what are the sizes of matchedAsk and ask in the line in your first reply? Check your values for i and x just before you execute the statement matchedAsk[x] = ask[i] .
I think in the second reply you have it going to one past the end of matchedAsk so that's not helping either(I'd have to go over the iterators but I'm not even sure one element is being copied there).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you ballpark a region where it crashes? If you have a debugger see where it crashes or put in some cout statements in strategic spots to note the progress. Then I (or someone else) can take a look at that specific spot.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I just responded to your other post (I had figured you had marked it as solved and changed your mind, I didn't know you had started a new one) with a concern about your aver_h in your AverHigh function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, it's a 2D array. Think of a 3D as holding values of a quantity that vary based on both the row and the column they are in. What you've done is essentially constructed a 2D array out of what could be 2 distinct 1D arrays(one holding the highs and one holding the lows)for ease of access.

I'm going to presume you're talking about line 14 above. I told you that 2D arrays are not accessed that way back in post #4. I'm not sure where you're getting that idea from but it's definitely wrong. m_t[row][col] is correct way(unless you want to address it by pointers but there's no reason to do that there).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Display(1) wouldn't work unless your method has a parameter. You could make a bunch of methods called Display1 thru whatever, but that may not be the most effective approach. There are a number of options open to you with string arrays too (so making an array and knowing which elements to pick and combine, etc.).
Definitely look up classes. I've seen people working on RPG type games that expend a ton of effort on sections of it that they could have easily done in minutes with a loop structure or the like. So needing to organize your code into "functions" is at least a step in the right direction.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay,so the deal seems to be:

void func(int arr[][2])
{
   //Yada
}

int main()
{
    int arr[2][2] = {{1,2},{3,4}}; //I don't think this makes any difference
    func(arr);
    return 0;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

func(&arr[0][0]); which is just func(arr); If your book is confusing you look for some examples on the net. You need the brackets in prototypes and function definitions but NOT when calling the function.

Arrays are passed by pointer (so actually the value of the address) so when you type int a[] into the arguments of your prototype or definition, it really degrades to int * a . It's not actually passed by reference.

When you define your function as void myfunc(int a[][10]) it ends up being void myfunc(int (*a)[10]) (I believe, I may be off on that slightly) so passing in the address of an array int a[3][10] a is equvalent to (*a)[10], so the call would be myfunc(a);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think what you need is a static method within Program to write out some text on demand.

class Program
    {
        static void Main(string[] args)
        {
            Display(); //display your outside message
            Store();   //display your store's wares
            LeaveStore(); //up to you to implement
            Display(); //display outside message again
        }

        public static void Display()
        {
            Console.WriteLine("It was a dark and stormy night");
        }

        public static void Store()
        {
            Console.WriteLine("In this store you can buy a cola, french fries, or a sandwich");

        }
    }

Mind you it's not an ideal solution but it would tide you over until you learned more about classes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I know zero about SDL but do you have all of the directories set up properly?
The includes go under the Project/"YourProject"Properties/ConfigurationProperties/C-C++/AdditonalIncludeDirectories

You'll also need to put the libs directories under the Linker/AdditionalLibraryDirectories of that same Config Properties menu (and the names of the libs under the Linker/Input/AdditionalDependencies))