jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The arrays are not passed into the functions with the []. I thought I went over that (EDIT: I did put the brackets around the t by mistake in post #2 but nontheless). Abhimanipal is right, I did not notice that before. You need to declare the array in main() and pass it in to all your functions. I wouldn't make it global.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't change the datatype of the definition you need to add the double before m_t[] on line 41. Changing it to int will conflict with your prototype and exacerbate the problem. If the arrays are 2D you must specify the second dimension in the prototype and definition, and you can't address the array with m_t(i,j) in C++. I'm not completely confident I know what you mean by priming read but I don't think so.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are missing the datatype for m_t[] in your function definition. You are passing m[t] into your functions in main() improperly, you do not need the [].
Take a look at line 51 versus other times you have used a 2D array. If you want to keep m_t as 1D you'll have to compute the index based on i,j. If not you'll have to rework your program.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

System.Drawing

The ones with the periods are the C# libraries System::Drawing is correct.

Can you post your point.h? If it is an unmanaged class (i.e. is not a ref or value class) you will probably not be able to incorporate the managed code (the .NET Color portion) with the unmanaged class.You can use it freely in Form1.h because Form inherits from System.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

rand() % 2 is especially risky when it comes to getting the same result every time (for reasons I'm not interested in detailing at the moment).

Good to know and noted.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Part of the problem is that if your program makes it through the two while loops without finding a "?" then set is still equal to false so the while loop runs again and again. You may not even want the while loop.

Also, you may want to put in a break statement (to get out of the for loop) after each of the set = true; statements, since you don't want it to run through the second loop if you've found "?" in the first. In the case of the first for loop, you'll need an additional if statement to break from the while loop/skip the second for also.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, you need to

#include <time.h>
and then one time before you call rand() (so e.g., at the top of main) call
srand((unsigned)time(0));

which seeds the random number generator

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So have your routine choose either 0 or 1 (so use rand() % 2) and then select the appropriate number with an if statement. I'm sure there are plenty of other (and better) ways to do it but that's off the top of my head.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For some reason if you put two spaces after each element instead of one then all the numbers come out. I can't figure that one out... but that means they are all in the array at any rate.

There are some other problems like putting braces after your else statements to make sure that it includes,e.g. lines 100 and 101 in your last full code listing above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you looking to choose a number within that range or are you looking to choose between one of the two numbers given?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
for(int ROWS = 0; ROWS < 6; ROWS++)
{
        for(int COLUMNS = 0; COLUMNS < 4; COLUMNS++)
       {
            inputFile >> ShippingData[ROWS][COLUMNS];
            cout << ShippingData[ROWS][COLUMNS]<<" ";
          //this loop is going for each column in a particular row
         //after each element there is a space
        }
    //we are here after a row has been completed (after we've gone 
    //through all the columns
   cout <<endl;  //or cout <<"\n";
    //so at the end of the row we place a newline character  

}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you want it in a table put a newline after the inner loop but before the close of the outer loop. It just happens to display that way, it's all in the array in rows/columns.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried so far?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are trying to output shippingData on line 87 which will give you the array pointer when you output it. You need to output shippingData[ROWS][COLUMNS] . Output a space after each one so you can see the values separated out (and if you want put a newline outside of the inner loop at the bottom to have it put each row on a new line).

Step back and take it slow. If you're rushing through it you're not thinking it through...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

ShippingData

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change your array back to float and it works.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Does your file have the labels in it or is it just the numbers?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take out the while loop on line 85 and move line 84 to 91 (deleting line 91). Your for loop is collecting the data points you do not need a while.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

WTF

Read the comment. He had tacked this onto another thread. It was assessed in that thread and after that it was split off by a moderator.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you check if the file is opening properly (you had it in the other version but it's not in this one). I would say if it is opening properly make a little program to test reading in the file by itself.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You never took any input from the file.

replace line 4 (in the second snippet) with inputFile >> numbers[ROWS][COLUMNS];

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Looks like you did it pretty well. I can think of two options, the first would be to report the collision to the user and not file the word.

The second would be, if you have a string holding your word, nothing is stopping you from appending a colliding word onto the end of the word occupying that position and using a space or comma or any other symbol as the delimiter. You would then need to account for this when you are outputting the strings at a given index. I don't know whether this is a good practice or not, but would work for purposes of your assignment.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So this is something you probably want to read in before you get to that stage of the program. Will the file always be in that format?

If so, make a 2D array for it, use a nested for loop and read each element in:

for(i over rows)
     for(j over cols)
           filein >> my2Darray[i][j];

If the file size isn't going to be known at run time we can make some adjustments. Now, when you get a package in that section of your program, use your two data points to determine the correct row and column of your table.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh geez. I glazed right over the period. My apologies OP. When you cited the error I thought you meant the .eof part.

Figure out what you need to read in from the file and when (e.g., if the shipping zone is 5 I need the second row, third column or whatever)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Substitute what I wrote for lines 7-9 in your snippet.

Keep in mind it's only reading into one variable so you'll probably get the last value in the file. If you have more things you want to read in, you'll need to read it into an array. If that's the case, create the array and use the while loop I gave you to read into it, but add in an index value which you increment in the body of the loop.

Edit: and if you want to read the "shippingzone"th value just put a loop counter where your weightcategory variable was:

int zonecount = 0;
while(zonecount < shippingzone && charge >> shippingcharges[weightcategory][0])
{
    zonecount++;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make table a private member of your class. Use a "setter" method that takes in the value, applies the hash function and puts it in the proper cell of the array.
ADs point is valid and important as not all inputs to your hash function will hash uniquely, causing collisions (how can you store 2+ elements at the same index of the array?). Using a vector allows you to hold multiple entries at the same position. That way it expands as necessary and once you need to retrieve something just step through all the members at that particular location.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use your >> statement to drive the loop:

while(weightcategory<7 && charge >>shippingcharges[weightcategory][0]);

(since it's a one line statement put the ; after it, but if there's a body to the while don't put that one in)
That avoids having to use the eof at all, which can cause other problems like reading in the last line twice.
You could even do something like test for the weightcategory before you go into the while and take that part out of the test condition, since weightcategory doesn't change in that loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In order to print something using a cout statement your function must return something (a string, int, double, etc). Your print() method is void. Just call your print method on its own without sending it into cout.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's curious that you named this program the "dowhile" freight cart. I think a few do/while loops will help you here. Wrap one around the meat of your code like from 13 to 50 and have the loop exit if the user selected 2 (you can leave your one if statement in there since if the response is 1 it's going to do all the processing). Then, each time you are re-prompting the user for an invalid response, use a do/while instead of the if statement.

As far as the other problems, do a quick "desk check" of your program by hand and make sure all the groupings are ok for the if statements.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thank you VernonDozier, I can ensure you that I always try hard myself before asking anything on the forum, the reason being that I want to learn how to program.
Thanks for posting the code, I had a look at it and I don't think I could have done on my own though, because there are still lots of things I don't know, like your directives

#include <ctime>
#include <cmath>

(never seen them before) and like boolean variables just to name some of them.

Thanks also for the clarification on the array, it's better now :)

ctime is the version of the C header time.h meant to be used in C++ code
cmath is that of math.h
(there is cstdlib for stdlib.h, etc., etc.)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put the curly braces like Nick Evan was saying. If you don't have the braces only the statement immediately below the if statement is associated with it. Put braces around lines 28 to 30. Now that whole grouping is associated with the top if statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also: curly brackets! They're more important then you think.

We're working our way up to that.

@OP: No, you can only use the comma for variables that are of the same type.

char choice;
int weight;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How did you declare it as a char? Change it from being a char to an int.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

weight should be an integer and not a char. You were comparing the ASCII value of the first character (so if you typed in 70 you'd only get the 7 as a character variable holds exactly one character, and 7 has an ASCII value of 55 which is less than 60).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

doesnt work, it comes up with some error msg saying before else


and heres the full code

Can't be the full code, where is weight declared? Paste your exact code, don't try to paraphrase.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Could you post the complete code? The error is not apparent from what you have posted.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Next time please use the code tags

[code]

code goes here

[/code]

Why do you declare choice after you try to write to it? You need to move int choice = 0; before std::cin >>choice;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Select the whole Form1 window in the designer (not the webbrowser bit) so on the properties window at the top it should say Form1 (or whatever you called it)

restrictment commented: Thanks for the help! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Go to the designer in your application and click on the Form1 window (or whatever you named it). Go to the properties menu on the right (if it's not there go to View/Other Windows/Properties Window. Click on the lightening bolt to get to the events. Go to load. Double click the empty cell next to it. An event handler will be inserted into your code. Within that type webBrowser1->Navigate("http://www.google.com"); (specify the name of your Web Browser object) Now when your form loads you will get google (or change it to something else -- or as a special exercise let your user specify it as an option ;))

EDIT: I'm not clairvoyant lol -- I've been through a similar tut in C# eons ago. But AD is right and you posted your code anyway, I just lagged behind everyone.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're not too far off.

With c-strings (strings terminated in '\0' as opposed to std::string which I'll get to in a minute) the variable is essentially a pointer, so saying

char * str1 = "Hello"; //a '\0' is automatically appended at the end of each of these
char * str2 = "Hello";

asking str1 == str2 will come up false every time because the pointers are not equal, they are stored in two different spots in memory. This same idea holds true for character arrays. Hence there's a need for a function like strcmp which does all the finagling for you.

On the other hand, std::strings, when you have

#include <string>
std::string mystr = "Hello";
std::string mystr2 = "Hello";

mystr == mystr2 will be true because the std::strings have an overloaded == operator (essentially a custom recipe specific to the class as to which components of the strings should be compared against each other).

Switch statements in C++ (and C) can only take ints (as well as chars which are basically 1 byte integers, and enumeration types which are implicitly converted to integers). It's been a while since I used VBA but it might be closer to .NET, where like in C# you can use strings in a switch statement.

I've probably glossed over some important points but others will be able to clarify if necessary. I may have known the internals of some of the string functions at one point but I …

daino commented: Great Answer +3
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh trust me if there was such a book, I would have found it by now, lol.

If you're also looking into designing IDEs that you can use with an existing compiler check out http://damieng.com/blog/2007/11/08/dissecting-a-c-application-inside-sharpdevelop -- the book is free and legal.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You should use a switch statement

char letter;
while (cin>>letter)
  {
    switch (letter)
      {
        case 'd':
        case 'D':
        case 'e':
        case 'E':
         //code here
        break;
       }
   }

There are two different variables in the OP's if statement, your approach will not work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: use the method String.IsNullOrEmpty()

You may want to change around your for loop into a while or do/while loop. You could use either of those structures to make sure you have at least 1 item in each and keep re-prompting if you don't.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Everywhere you were accessing ".number" use your getter (like in lines 154 and 164). I don't know that you need the friend class bit up in the card class if you use the getter. Debugging the game itself is going to take time and making sure things are getting where they need to go. Start putting some cout statements around critical parts so you can see what the values are (like the cards you drew and the value of each, etc).

kvprajapati commented: Great! We appreciate your help. +9
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I meant more like:

int getValue() { return number;}

(no implementation is needed)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Nothing even that fancy. It'll go around line 30 or so (within your card class declaration). One will have the return type int and take no arguments (then put the braces and the return right after it) and the other will return Suit (and be similar to the first one).
Then once you have a card, just use the .getValue() method you just implemented (or whatever you will call it) to get the value of the card.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't give shuffle any arguments it knows the deck it's shuffling already

Make a quick "getter" for card that returns the card value

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

in
main(); or card if not in game

Good way to hedge your bets there ;) Still belongs in game, but remember anything you declare (when not allocating memory) in a method gets destroyed when the method terminates. Where do member variables belong? It's a member variable of your class game.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See if you can figure out what the error message means on your own. Hint: rework your main so that returning from that function you'd be exiting the program. Another hint: When do void methods return? Exploit this to let everything finish up when you press n and just respond to the Y prompt.

A sneak preview: figure out where your deck array really belongs...