jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This site is indispensable: http://www.cplusplus.com/reference/ (their tuts are good too but it's nice to be able to pull up a function and get a quick snippet to go with it)

http://web.cs.mun.ca/~michael/c/ascii-table.html is a nice plain ol' ASCII table.

For more advanced stuff check out http://www.eternallyconfuzzled.com/. It's very well written (by DaniWeb's Narue).

I'm sure there are hundreds of thousands but those are the ones I use most frequently.

Lusiphur commented: Thanks jonsca, I knew I'd get a reason to give you rep eventually!! :) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

TryParse returns a bool as to whether or not the conversion was successful it might look something like this

using namespace System; //up at the top
if (Double::TryParse(textBox1->Text,value) && Double::TryParse(textBox2->Text, rate))
{
  result = (1/rate) * value;
  textBox3->Text = "$"+result.ToString();
}
else
  textBox3->Text = "Unable to convert parameters -- ERROR";

Or something similar to that (e.g. instead of the error message, set value to 0 and rate to 1 and print a message out in the debug)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're very welcome.

You don't need the TextChanged handlers for the 3 textboxes as they are not doing anything at present. TextChanged means the method will run with each character you are typing for example (or when you backspace, etc).

Have value be either a private member variable of your class -or- a local variable to your method, but not both. If you need "value" elsewhere in your class keep the private member variable. If not, just have it be local like rate and result.

To place the dollar sign in front just do textBox3->Text = "$" + result.ToString(); The only other thing is Parse, but I explained that one already. If you type bob into the textbox the program is going to throw an exception.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I have heard (I have not read it) that Ivor Horton's Beginning Visual C++ 2010 (or the 2008 edition) has a fair amount of C++/CLI. I've never found anything satisfactory in the tutorial department for CLR Winforms (I've adapted my knowledge from C#).

One thing I see in the above code is that total is undefined when you get to the switch statment.

You don't need to put "value" as public (and that version would be masked by the one in the click handler anyway) unless you need it elsewhere in your code, in which case only declare it as a variable of the Form1 class. The TryParse should be called right in the click handler too. You don't need to calculate result within each case of the switch statement, you can postpone it until the end.

A consideration: I would use all doubles instead of making the other two floats. You run into danger of losing some precision in the conversion.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to include "Lottery.h" in LotteryFactory.h (like it has it in the code listing on the site) since you have a Lottery object in the LotteryFactory class. You'll also still need to have Lottery.cpp as a part of your project for the methods of the Lottery class.

Including Lottery.h will also get rid of the errors surrounding cout, endl, etc. because it has the the statement using namespace std; Are you trying to learn the C++ along with how to use Eclipse? This tutorial presumes a lot of prior knowledge.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thank you jonsca for your insightful response! I researched the Double::TryParse and I believe I understand how it works. Although I am unable to figure out how to implement it?

Double::Parse will throw an exception if there is no valid conversion between the string and a double. TryParse returns true if the value converts. I misspoke earlier calling the parameter an out variable (which is what it is considered in C#). Basically create a double variable and pass that in as the second parameter: Double::TryParse(stringtoconvert,doubletoacceptvalue) and you can put it in an if statement to make sure you are really getting your double.

So in your case the string to convert will be textBoxWhatever.Text

I should have also stated this was is my attempt at writing a "Forms App" and it's confusing the heck out of me. :)

As for your question on how I would signal the conversion to begin; I assumed I could use the "Convert" button to call the event?
Thank you again for your assistance!

No worries. It takes some getting used to. Luckily a lot of the dirty work is taken care of behind the scenes.

Yes, you're correct, so your formula will go into that ConvertButton_click event (or whatever the name of your button is).

Anatake commented: Thank you for helping a newcomer! +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster


Hey again! Sorry for what? You mean because someone else got around to telling me what was wrong with the code before you? If that's what you meant, don't sweat it!

It was more speaking to my having tunnel vision LOL

Anyway, you always try to help and I really appreciate it. Take care!

Never a problem!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm definitely very sorry to hear about your father. I would look into as much information about the hardware for his setup and what interfaces it uses and what APIs are available (if any, they may not be public). There might even be a setting that could be adjusted to make it more reactive for the time being.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

so you need to remove
the comments to have the book_list declared.

mit, It wouldn't let me +rep you (since I did yesterday) but yeah.

Yeesh (slaps my forehead), sorry Bobbie Jean.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try to cout tmp on both 601 and 602. Make sure the file is opening and you're actually inside the while loop. If it's not opening check the file itself and make sure it's in the right directory (one way to check is to write out a file to the same directory and manually make sure it's there).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you have a good text to follow? It's not so good to develop bad habits early on as they will stick with you. Even looking around at (a majority) of the code on this site should give you some idea and there's countless examples of menuing systems.

Functions should be called and the value returned and then called again if necessary later on. They shouldn't be an entry point into the spider's web.

I'm not trying to be harsh here, btw, just trying to help you use what you have to make a much more effective program.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 628 is not the right syntax:

if (menuchc == 'y' || menuchc == 'Y')

I think that's the least of your worries though. This is quite a, er, creative program. There are a lot of constructs here (goto and calling main explicitly) along with a lot of non-standard stuff that will take away any portability.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to make sure that you have all the files in the same project, or if you are compiling on the command line put BookRecord.cpp first.

As for devC++ the version of g++ it uses is too out of date and the IDE itself is no longer being developed. You should be fine with whatever compiler you have now, we just need to figure out why it's not liking your other CPP file.

BobbieJean commented: Jonsca always tries to help and always seems to give great advice!!! Awesome daniweb member!!! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have text representations of the numbers for each of the boxes. Use the Double::TryParse to get the value. Look up the syntax of it as it uses an "out" variable to return the double.

Everything in .NET GUI programming is governed by events. Can you think of a means to signal that the calculation should be done (like how would you do the equivalent on a pocket calculator)?

Take a run at it and post back with any questions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

"used" is a std::string so it uses the find() method particular to strings. See http://www.cplusplus.com/reference/string/string/find/

versus the <algorithm> version (your first example)
http://www.cplusplus.com/reference/algorithm/find/

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try changing the MaximumSize property of the Form1

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Not sure. Probably setting the Location to {0,0} (or as close to it if it needs room for the border).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If I recall, you are using Winforms?

Here's an example in C# that you should be able to adapt pretty readily for C++/CLI: http://www.codeproject.com/KB/cs/csdynamicscrres.aspx

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Welcome Bill Gates II

Bill Gates is already Bill Gates III LOL at your comment though.

Another Question, seriously, why is there no C++ Software foundation?

Since there is an ISO standard for the language why would you need such a body?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

but i know this is not the way to code perfect

Unfortunately the whole system of packing all of this stuff into the header file makes it inherently harder to "code perfect," so it's not your fault. Keeping it at the class level is at least organizing it into one object even though it's a mishmash of all your controls and stuff.

Rather than use the unmanaged code as ShadowScripter suggested (which is perfectly valid under different circumstances but can be a bear in the managed .NET code under which the OP is working), you can use a System::IO::StreamReader object (see here) instead with its ReadLine method.

I think it would be easier to keep the individual data on separate lines in the text file (as in ShadowScripter's example) and just do each readline into a separate variable. I think it's great you want to save space in your file but this makes life much easier. You could conjoin ReadLine with the String ^ split() method of the line you've read in but you'd have to keep track of which was your "Name:" "Age:" labels and what was real text. Unless you require your text file to be human readable, you could get rid of all of the labels and use space as your delimiter.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried so far?

Can you take in the input from the user? Do you know the formula for the area of a square (it's not hard and should be on millions of internet sites if you really don't remember)? Bring those two together and output the result.

Write parts of it and check to see that they work before continuing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change your loop from

while(!fin.eof())
-to-
while(fin >> temp)

and eliminate line 17.

See http://www.daniweb.com/forums/post155265-18.html about why .eof() exhibits this behavior.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would lean away from Dev as (my understanding is) it's very buggy and no longer under development.

The Visual C++ Express Edition is a good option but if you want to do winforms you're stuck with C++/CLI which is cumbersome (you can use the Win32 API within Visual C++ too but there is a learning curve there).

You could look into Code::Blocks (which comes with mingw, the Windows port of g++/gcc) and supplement it with something like Qt or wxWidgets or others for your windowing toolkit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Scroll further up in your Form1.h file and you'll find a bunch of variables being declared (your listbox and buttons, etc., it will say private: System::Windows::Forms::Button^ edit_button; or the like). Amidst those put your private: String ^ SelItem; .

It won't be "global" but I don't think that you want that either, it will be local to your class.

Then just use it within those methods (being aware that since these are message handlers they are not called in any particular order, so the user could click save_edited before edit_button).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're going to need to implement something like this: http://www.codeproject.com/KB/recipes/csnsort.aspx. It's probably better to make your numbers into a System::Collections::Generic::List<String^> which has a sort method in it. To use the sort like you want it to, you'll have to making your own class that inherits from IComparer and passing that object to the sort (see also http://msdn.microsoft.com/en-us/library/234b841s.aspx).

If you like your method better you can probably use Int32::TryParse to batch convert your String ^ arrays into int arrays. This all depends on how you will use the numbers downstream.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

1.) Every element is assigned the value zero
2.) Accomplishes the same thing
3.) No different than 2.)
4.) Since you are defining the array you don't need to tell the compiler how big it is

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I didn't even notice it before but never use void main() main() always returns an int according to the standard.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's an extra '\n' (newline) in the stream (from when you press enter after the number) that's being taken in by the first getline as a signal that input has ended. So it's getting skipped. ShadowScripter's idea is correct and probably preferable (though you could use stringstreams as well) but an alternate would be to put a cin.ignore() before your getline statement to sop up that extra '\n' .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It depends on what libraries you use with your code. If you use all functions from the standard libraries your code should be highly portable. See: http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library. Beyond that, you'd have to see if the library was identical for both platforms (some of them are, with the differences between the two are bridged "underneath the hood.")

If you use something written specifically for windows (e.g., Win32 API) it's almost guaranteed not to be portable. However, if you use a library like Qt for your GUI you should be able to compile it on Windows, Mac, and Linux (wxWidgets is also compatible across Windows and Linux I believe).

That probably gives you more questions but hopefully clears some of it up for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out this article: http://www.codeproject.com/KB/cpp/DoubleBuffering.aspx

I've not done much in the way of Win32 API so I can't help any further than that, but this is the general concept of what you need to do.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you using WinForms? If so, turn on the DoubleBuffered property (select your form in the designer and select the cell next to DoubleBuffered on the right hand side, set it to true). I'm not sure how to do the equivalent in other platforms.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you asking why you can't compile it as a Windows program or am I misunderstanding you?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm still waiting on the source from your polynomial approximation program. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Does that qualify you for the nickname "Broke" Winder?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

My unofficial answers, just relaying (and re-relaying) the info I've heard:

Hit the search key with nothing in the box to get the advanced search. I think Dani is working on it, see this post http://www.daniweb.com/forums/post1229170.html#post1229170 and a few posts down.

The "mark forum as read" 'bug' is a feature of vBulletin (the underlying framework of the forums, as I understand it). There's a post about in Area 51 but rather than copy and paste it I'll let Dani or Davey give you the official word.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure if this is to what you are referring but a struct can have a constructor just like a class does (the only difference between the two is the default access of the variables, struct everything is public by default and class everything is private):

struct element
{
   int var1;
   char var2;

   element(int varone,char vartwo) : var1(varone),var2(vartwo) {}
   //this uses an initialization list but doesn't have to
};

So in main you can take the input into temporary variables and then pass them all into the constructor when you create your object of type element.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please post a piece of your code around that area so we can see what's going on.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Trace through your program by hand and see what happens when you enter 0 (hint the while is going to spin forever because integer == 0 will always be true -- which causes the loop to continue not stop).

Also do this for finding the highest and lowest numbers. You'll find you'll need to rearrange your loop to encompass more of your statements. As it stands your code only goes through once if the number is nonzero and gets stuck in an infinite loop if it is zero.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

NVM I missed that you were replying to my second post

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The for loop was solely for 80-117 and would actually be inside your do/while loop.

You should be able to have something like

//some pseudocode
WHILE(true) //says same as your while(1==1)
{
"Enter 'e' for expression and 'q' to quit"
 READ IN a character
 if(character is 'e')
 {
      //your other code
 }

 else if (character is 'q')
     return 0;  //since your function returns an int

}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Help with this please,Im trying to learn c++ and i cant figure this out

There is no C++ in what you have written there. That is C. I have asked a moderator to move it there. Also, don't be so quick to bump your thread as it takes time to get a response.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

main should always return an int, void main is non-standard.

You don't need the ; after line 30

Line 37, that statement does nothing.

Most importantly, never use gets. It is too easy to overflow the array to which you are writing as you have zero control over how many characters the user enters. Use fgets instead.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How do you access the elements of an array? Hint you did it just fine about 4 lines before that.

It's not critical but usually the notation counter++ is used instead of counter = counter + 1 Also Please use code tags [code] //code goes here [/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

While we're updating this, is anyone else not getting subscription notification emails?

No, I haven't gotten any since late on the 7th.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Because comparing the value in dvar1 with 'q' can be dicey, the best solution would be to make a sub menu (I know it's not exactly what you want but aside from reading in your expression as a string and parsing it out that may be the best way).

The menu would say "enter e for an expression and q to quit." If they select 'e' you can move on to 127, if they select q you should return a value (e.g., 0 but it doesn't have to be) so you can return to main1 without having to call it explicitly (when you are calling main1 like that it's a new copy of main1, not the one you originally came from).


Look up for loops for lines 80-117

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Could you show more of the surrounding code? (any data that's put into the vectors beforehand)

VC++ 6.0 has a compiler that is much less standards compliant than the more recent ones, so it's no surprise that 2008 kicked out the code and 6.0 didn't.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

My apologies to pvfloripa for the misunderstanding.

Nick Evan commented: :) +15
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I have a couple of 8 bit Nintendos around but nothing compared to this. I technically have every computer but most of them are just mobos knocking around in a box somewhere.

Ah, "one man's trash is...", well, another man's trash that's euphemistically called something else :D All the more power to you Happy!

@Nick did that woman come with the computer?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

VB gave you the correct functions for Win32 API, but are you using the API or MFC or .NET?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

From www.cplusplus.com about the operators < > <= >= etc:
http://www.cplusplus.com/reference/string/operators/
"These function [sic] depend on the value returned by string member compare."

Regarding compare:
http://www.cplusplus.com/reference/string/string/compare/

"The member function returns 0 if all the characters in the compared contents compare equal, a negative value if the first character that does not match compares to less in the object than in the comparing string, and a positive value in the opposite case."