jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hmmm. Okay. I'll toy around with my add-ins. Thanks for verifying.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This may seem like a random question, but do you have the full version of Visual Studio? If you're trying to compile MFC code with the express edition you might run into this. If you're not, maybe one of your headers is missing or corrupted.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Happy Thanksgiving!

This is a minor annoyance, but it's happened to me 3 times in 2 days so I figured I'd letcha know.

I'm using Chrome 7.0.517.44 and when I've gotten a PM, the screen goes "dark" (as usual) but no dialog pops up and the browser gets stuck (I have to hit back to get a working page again).

It could be just me, but I wanted to see if anyone else had this problem.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

http://www.cplusplus.com/reference/clibrary/cstdlib/strtol/

Note that it takes a C-string (so if you're using std::string you need to use the .c_str() method)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to take a quick trip through your textbook on scoping.
With any set of braces (known as a block):

{
  int myvariable;

  myvariable = 42;
}

cout << myvariable;  //compiler says: who? => error

by the time you want to access myGame's methods at the end, it's already destroyed since it was in the while block.

Also, thanks for trying to use the code tags, you can probably still go back and edit this post to fix them, they have to be [code] (2 brackets)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post this portion of your code? You are probably trying to call a function that is not declared.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make search_num return a bool, it'll make life easier. Be careful with lines like 46, just assign 0 instead. False might work, but it might not, I'm not sure.

Look at lines 54-56 for one of the major sources of error. What you have done is declare 3 variables within your constructor that mask the three declared in the private section. When your constructor completes, those variables are destroyed and the others go uninitialized. So take off the int from the variables on 54-56 and you'll be fine.

In terms of your compiler error, change your srand line to srand((unsigned)time(0)); so that you explicitly cast to the unsigned that srand wants.

I'm sure those aren't the only issues but it will get you started.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Which compiler are you using? They do have a makefile for VC++ version 10. If you have cygwin, etc. you can use the build instructions for *nix.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please post the code that you tried or a subsequent attempt without using switch (as neither one requires it per se).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please share here what you know about that ,, :)

Please feel free to do the same!

Please post the code you are having trouble with or at least a rough pseudocode outline of what you think should be included to start.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

As far as the second 3.14159 (with setprecision at 9), the mode is still the default one, so the extra zeros are not displayed (from the cplusplus.com site
"On the default floating-point notation, the precision field specifies the maximum number of meaningful digits to display in total counting both those before and those after the decimal point. Notice that it is not a minimum and therefore it does not pad the displayed number with trailing zeros if the number can be displayed with less digits than the precision." (http://www.cplusplus.com/reference/iostream/manipulators/setprecision/)

In terms of your request, what is your objective? (it seems to be changing from your original request) You could selectively format the number based on the digits after the decimal point, but that would get tedious. You are asking to have the default setting on some and the fixed setting on others. Perhaps if we knew what you were trying to accomplish...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Something like http://www.mpir.org/ (or http://gmplib.org/ if you're on *nix). Check the documentation for the largest number allowed, as 500! may far exceed it. Remember that 500! is a monstrous number! Check to make sure your assignment isn't to approximate it somehow.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to call your function for those values... Passing (0,0) to A gives ____ ?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

AD's got it I think: http://www.daniweb.com/forums/post1395916.html#post1395916 (OP double posted this)

The problem is, the order of which the ++ and + will happen is implementation dependent.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I compiled it and did not get that warning, as it seems you have initialized it properly. There are a host of other errors. Does line 77 look right to you? There are 6 more errors like that. Someone had pointed that out in an earlier post.

Also, for example, on line 68, you're mixing doubles and ints, which is ok, but you're assigning it back to an int, which will truncate the decimals off of your value.

A minor thing, you have your constants defined at the top, but you hard coded the values in later (for 0.08, etc.).

EDIT: You are missing a couple of semicolons too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just an aside, you shouldn't use .fail(), use .is_open()

.fail() is for checking when a stream reads something it wasn't supposed to (like trying to read a string into an integer).

There's one way to find out exactly where your program is failing, run it in a debugger and single step through your method.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would hold off on the sum function for now. I had told you that you are summing 2 arrays that are uninitialized so there's going to be garbage in those slots in A and B.

Work on getting the input in and shifting it down (and "padding" with the appropriate number of zeros. Hint, keep track of how many numbers the user entered and have them type 999 to finish (otherwise they have to enter 29 numbers each time).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, you had it right going from 0. I meant leave SIZE = 30 and have the loop go to SIZE - 1 instead of SIZE. There is no -1 position in the array. Think about it, 0 to SIZE - 1 (provided SIZE = 30) will give you indexes 0 to 28, which you can shift down to indexes 1 to 29 as the assignment prescribes.

Write down (pencil and paper style) the steps it would take you to accomplish this and draw out the array. It will be helpful.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Repost your (current) code please.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok, but you haven't made any progress on your methods... Take more than a few minutes, think it through, code, test, code, test, and see what you come up with. I'm not going to do this for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The best way to do this is with stringstreams, but that's probably not allowed in your course either. I add this because someone is bound to come along and say "why don't you use stringstreams??"

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I never said it was correct. I meant that get_data should take no parameters at all, so your method definition is correct, but the call in main() is not correct either way.

So if you know the number of strings, make an array of strings that will hold 5 strings. Start at the beginning of the original string, read until you hit a space and store that word (hint, the += operator may be helpful to you). Do this for each word until the end of the original string.

Read your text to determine which property of std::string you can use for this. Hint: how do you access the individual characters of a string.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 31, still incorrect. According to the definition of your get_data function, it doesn't take any parameters, which is correct as you will write into line via your get_data.

For the extraction, think about what it means for something to be a word. There's going to be spaces (which means you will need to use a getline function in your get_data). Easier if you use a vector to do it if you don't know the number of words you are expecting, but if you can't, use an array of strings that has a high dimension.

Not to be critical, but you need to plan some of this out with pencil and paper before trying to code it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For the extraction, are you allowed to use vectors?

Also, please repost your current code. Make sure there are no stray "!" in it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ask the user for a starting coordinate (row, column), orientation (horizontal or vertical), and size of ship. Make sure the ship will fit in the area (i.e., isn't too long in one dimension or isn't already taken up by another ship). Change the value of the board at the appropriate coordinates to "P" or "C"

Try that and see what you come up with. If you're having another difficulty with it, post back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try again with line 30, you just need line, there's no need to put the type when evoking a method.

Flip the brace around (i.e., "}" to "{" ) on line 36 See if that straightens out some of the other errors. Otherwise, check over your code carefully, fix any blatant error you can find and repost it.

39 has the stray "!" that needs be gotten rid of

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What errors are you getting. What you have put forth there doesn't compile due to a set of mismatched braces and the stray exclamation points. Also, you're passing "string" to your method on line 30, which is incorrect.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I tried a few things, but I didn't come up with a solution. I don't use this date format on my machine so I couldn't test it fully anyway. You could always use the dateTimePicker1->Value = DateTime(year, month, day); overload (where those are ints), but I'm not sure that will get you what you want.

Failing all that, and if you don't get any more replies over here, it couldn't hurt to ask in C# as there are folks there that deal with this .NET stuff and might have the answer at their fingertips.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

At least make some attempt at the StringModify methods first. Just posting the skeleton provided by your instructor isn't sufficient.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's a function carried through by the C standard library. See http://www.cplusplus.com/reference/clibrary/cstdio/printf/ but read the examples first instead of the theory.

I wasn't endorsing your use of it, especially if your class is in C++. My google search was for arguments in favor of one way or the other and I included the link for completeness.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You still don't set your vector elements to any values. Line 29 does absolutely nothing.

If you've initialized a vector, you can set the elements like x[index] = index (or any other value for that matter). Otherwise you need to use x.push_back(index) (or any other value).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Instead of changing your size constant, why not run the loops on lines 30 and 37 to SIZE - 1? (your Sum function is going to have to be changed all around to account for the shifting and carries, so don't worry about that one for right now)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

and jonsca, how would i go abouts changing ti from 0 to 29?

Your input loops currently run to 30, make them only run until 29 (it takes just a small change)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You've "hard-coded" the 10 into your program, so if you change that number, you have to change it everywhere. You never use your second parameter.

More importantly, you never assign the return value from your function to anything. "avg" in your function and "avg" in main (which is declared right above it's use so it could have garbage in it instead of 0) have no relation to each other, as they are not in the same scope (skim through your book's section on scope to see why).

Just a minor detail, if your file is bad, you report that to the user, but you continue on with the program anyway.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

for(index = 0; index < score_length; index++); Something is amiss on that line. Check the end of it. Doing this causes the for loop to run score_length number of times with ";" as the line to be looped over.

You may want to pass the number of elements in the array into your function instead of size. Global variables are never a good idea.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look into the .push_back() method of the vector as well. Otherwise you are treating your vectors like arrays and they have so much more power than that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Nothing that I can see. What is the result you are expecting? (note that you don't have a newline after your cout, so your numbers are all crammed together.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need to make the arrays consist of longs, depending on your implementation and whether your computer is 32/64 bit it may be the same size as an int anyway. Really, you only need a datatype that will hold one digit per index of the array, but stick with the ints.

You will probably have to have the user input the digits with a space in between, as cin uses space as a delimiter.

In terms of the shifting, say your user enters 12. A[0] contains 1 and A[1] contains 2. You need to shift A[0] down to A[28] and A[1] down to A[29] (so count the number of digits and shift everything to right by total digits - digits in number.

No, your upper limit on digits is 29 so you can have a carry into the final digit. Your sum function doesn't take into account this carrying that must go on at each digit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think what you're doing is correct, but:

Why dont you use 'printf ()'. This function is much handier, and lets you input everything you want (and print every way you want it).

This is probably one that could be argued either way. If the OP's class is using iostream, it's probably a good idea to stick with that.

Not to take this OT, but there are some interesting arguments about that here: http://stackoverflow.com/questions/2872543/printf-vs-cout-in-c

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

jonsca,
thanks for that. I had a read at the tutorial, not sure if I understand it correctly though especially when it comes down to distinguish between fixed and default...

From that same site fixed means that: "the value is represented with exactly as many digits in the fraction part as specified by the precision field and with no exponent part." (presumably meaning that the implementation will find the closest floating point number that carries that value to a certain number of digits, and will not use scientific notation)
vs.
Floating point is a way to increase precision at the expense of the size of the number and vice versa. That is the default for cout.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to use the functions in iomanip. The decimals are there, they are just not being displayed.

So, #include <iomanip> and see http://www.cplusplus.com/reference/iostream/manipulators/setprecision/ . You'll have to set the fixed setting first like they do in the example.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the constructor you need to allocate memory for the array vector = new float[x];

Where have you done this step that AD indicated?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

O.K. What do you have so far?

Agreed.

@OP - what system or API are you using to get the mouse coordinates? Win32API? something proprietary?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What does the file look like, can you give a sample of a few lines of it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You want to include <cstring> (which is the old string.h from C that has strcpy, etc) instead of <string>. As you have it now, you are including <string> which has a class named std::string, which is probably causing a name collision.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the second one, length is a method of the string class, so therefore you call it on s directly, like s.length()

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

My similar issue had cleared up and has remained clear for months, despite having reported posts in the meantime. I thought you'd updated/cleared the cache on the server(s) to pull it off, Dani (I may be wrong as I know nothing of that fun).

You can celebrate both times you clear 1000, darkagn!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No problem, it was more the second warning that was important. Sorry I didn't specify that. It's saying that there's a path through the if/elses in that function that would result in not returning anything by the end of the function, which has promised to return something.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Glad you found the problem. However, local variables with the same name should "hide" the global variables, AFAIK.