jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Edit:
NVM your problem isn't the c_str(), userInput is already char.

strcpy (cstr, userInput);

userInput is a string * which means you have to dereference it using the -> operator, so userInput->c_str() @OP You still will need to include <string> if you are using std::string in your code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

and the worst is that they gave us this task before explaining the functions

I'm sure there are on the order of 10^23 pages online about functions and you probably have a textbook.

This is my interpretation:

string dec2bin(int decimal); //prototype

int main()
{

  //input a number "num" here
  //pass num to dec2bin
  //print out answer
}

string dec2bin(int decimal)
{
  //do your input calculations and your string manipulation
  //return the string to main

}
kvprajapati commented: I did't knew it :) +11
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

<Sorry, misunderstood the question.>

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

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

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

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

I'm not certain what the exact problem with your program is, but Dev-C++ is no longer in development, so the one that you can download will almost certainly have an older version of Mingw (Windows port of gcc/g++). That should mean that some portions of your program should run more readily on the Dev-C++ setup if they are less standards compliant. Since you are seeing the opposite effect, I'm not sure.

I did get some warnings when I compiled it with g++ 3.4.2 (which is about a full version behind but not as far back as the one that comes with Dev) and main should return an int according to the standard.

In function `bool checkBoard(int (*)[50], int, int)':
60: warning: unused variable 'counterD'
103: warning: control reaches end of non-void function
 At global scope:
186: error: ISO C++ forbids declaration of `main' with no type
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, that's not the right thing Lanor. I am perfectly capable of giving the OP a working program for this problem. He/she won't learn anything the way you have done it. (Besides, never use goto)

invisal commented: Sorry... my mouse accidentally click on -1.. Really sorry. +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh stop being mean :) Congrats!

Besides, I find it quite amusing that everyone else who commented has WAY more posts ;)

That's like asking a fish to stop swimming. "In my day," we never bragged about getting into the top 100, since there was no such thing. :P

Nick Evan commented: Back in the day we bragged about how many "stars" we had +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's the right way to do it with the if/else. Now all paths through that method will return a value.

In doing it the way you did, as long as your calling function could tell the difference between the error condition and the actual value requested as [0][0], but I'm not sure how you could do that without adding an extra parameter. I'm not sure what the best return value would be for the error. That'll be up to your design.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://www.codeproject.com/Messages/3198006/Communicating-with-main-GUI-thread-from-worker-thr.aspx you can't write directly to the GUI thread as that could lock up your main application.

You cannot use an ofstream object. Any unmanaged types have to be transferred in between the unmanaged and managed parts through marshaling. Use a StreamWriter (http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx) but as it says in the documentation, it is not thread-safe. There is a Textwriter::Synchronized available, but I've never used it.

cwarn23 commented: Thanks for the hand. +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Great! Yeah, you were right on the cusp of it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's s bit confusing, but it seems to be asking you to apply sumN() to each element of your array. This would be a good spot to use a loop over each of the #size inputs. Keep it in main() and model it after your input loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your "else" is associate with the if(L1==L2 && L2==L3) you want it to be associated with the if(L1+L2 > L3) All I was saying is that if L1+L2 <=3 then it skips everything else and returns whatever is in the empty shape variable.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look at the condition on line 54. What happens when all of the sides are equal? Try testing for equilateral first.

Also, while you are restructuring the loop, what happens when L1+L2 <=L3 (I think you tried to account for it but be careful which if/else pairs are associated with each other)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: Write the bar graph out line by line. Draw out a sample by hand and see which values have stars printed on which lines. After you've figured it out using cout, send the output to your ofstream object instead. Give it a try and see how far you can get.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

can explain detail like write down the pseudocode and the whole c++ program.. thanks^^

This looks suspiciously like a homework assignment. Please let us know what you have tried first. Working the problem on paper will help you write the pseudocode, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if(Atmos->SelectedText !=Temp->SelectedText)

doesn't work for it?

If you wanted to do it succinctly you could step through each of the controls on the form, checking to see if it's a combobox, then checking that combobox versus all the other controls. The best way to mark them is to use the Tag property since there's no "is" keyword in C++/CLI like there is in C#.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The best method (though I don't have any advice on it) is using a background worker: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

yoni0505 commented: thanks +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's relatively easy:

#include <sstream>
//...
int numbervariable = 10; //or double, etc. or use your loop counter
std::stringstream ss;
ss<<"Firstpart"<<numbervariable<<"Secondpart"; //use it just like any other stream

std::cout<<ss.str()<<" is the string portion";
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put your code in an infinite while loop (using while(true) ) and break out of it when you want to exit. All of your function declarations would stand anyway and global variables would persist during the program execution, so I'm not sure what you mean by that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your temparray is exactly that. It's created within the local block of the function and destroyed when the function exits, unfortunately.

Pass in an array by pointer so that your function signature looks like

void arrayfunction(float arr[],float flt1,float flt2,float flt3)
{
   //load up the array here

   //still exists on exit

}

I suspect since you are using opengl that your function is really more complicated than this.

What you have above could work with some modifications, but I think the above way is much more straightforward.

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

I have not read it, but I believe the Ivor Horton Visual C++ 20XX {05,08,10} covers some of the CLR-Winforms (in addition to MFC, I believe).

The winforms programming requires you to use an odd dialect of C++ (called C++/CLI) so I think a lot of people avoid it because it's clunky and it's painful to interact managed and unmanaged data.

M$'s evil plan is to have people use C++/CLI as a compatibility layer between C++ code and C# and do all the GUI programming in C#, or that's the way I understand it.

If you want to do your GUI programming in standard C++ you'd have to stick with either win32 API, MFC or a third party library like Qt or wxWidgets.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What does DELIM consist of?

The reason you are getting one line is your ReadLine is not in a loop. You're going to have to read in a line, split it in two, drop the label, place the data in the array and move to the next line.

Geekitygeek commented: read in one line, then complain that you only get one line...aah newbies, whatever shall we do with you :p +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Fbody, your line 2 should read myString += " 123"; I believe.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No one is going to give you the code. You'll have to make some decisions about how you'll populate your arrays, whether you hard code the words into each or read them in from a file, etc. You can just search for the words in the array and output the word with the same index in the foreign dictionary. Anyway, take a crack at it and post back with further questions or, even better, code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Classes can have member variables and methods.

class Example //this could just as easily be a struct as both it's members are public
{
    public:
        int exampleint;
        void examplemethod() { //do something }
};

int main()
{
  int num;
  Example ex;
  num.method();  //int is a native type not a class struct or union, can't use the .(it has no methods)
  //the above line would generate a message similar to the one you had, I believe (I didn't compile it and can't remember)
  num = ex.exampleint; //ok we can access exampleint by the .
  ex.examplemethod(); //works as ex is an object of a class
  return 0;
}

However, in your case it is because it is not recognizing the type std::string because your headers are too old (at least that what it seems like).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: x ^ y takes the exclusive or (XOR) between the bits of the two integers it is not the proper operation. The pow() function of <cmath> is used for that but is not necessary here.

You are correct in needing a for loop. Try and figure out the value of 2 you need at each step (e.g., at 0 you need 2 raised to 0 which is 1, at 1 you need 2 raised to 1 which is 2, etc.) and find the pattern. Trace it out by hand if it helps you. Take another crack at it and post back.

Please use code tags when posting code [code] //code here [/code]

Fbody commented: well handled :) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Which code?

For the second problem, btw, you just need the MouseHover and MouseLeave events for the picturebox, changing the background image to picture2 on MouseHover and changing it back on MouseLeave.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need the arrow -> and not the . on lines 15 and 16 because theTime is a pointer.

shaynerossum commented: Thank you very simple solution. +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since you're new to programming, I will tell you some programming tips:

-Try to indent your code (inserting tabs or spaces when you're between brackets).
It will make your loops (for), your conditions (if) and all your code more easy to read and understand.

A very good point.


Additionally, putting your code in:

[code]

//code here

[/code]
will preserve the formatting of your code in the forum, otherwise all leading space is stripped from the post.

ddanbe commented: subtle :) +7
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

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

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

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

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

My apologies to pvfloripa for the misunderstanding.

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

He had the a^2 there. Doesn't matter, glad you got it working.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok, I'm not sure if when helping people figure out their code if you actually copy, paste and attempt to run the code, or if you just look it over, so I am going to explain what I have done and what the error is now.

If it's a compilable piece I usually try to run it, or if it's a function that I can couple with a small main to test.

The whole idea that tesuji was trying to show you would eliminate the need for 2 separate file openings:

while(inFile>>next)
{
   total+=next;
   totalsq+=next*next;
}

ave = next/counter;

Then use the formula on line 14 of tesuji's proof. ( sum(xi^2) is totalsq ).

Your problem with your current code is on line 52:

while (inStream >> next);
Griff0527 commented: Excellent at guiding in the right direction while making you think for yourself. +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The only code i found that could help me is here. Is it proper to be used in my case? Do I have to do a separate class for the list and for the node or can I define the node in the definition of the class?
Sorry for the question and thanks in advance!

Yes, that will work, but don't just copy their code you won't learn anything. Where you define the node and whether it is struct (all members public by default) or class (all members private by default) is not critical. The notation will be virtually identical.

This title is so inappropriate...

Yes that's true, but there's no way for the OP to go back and change it. I agree there would be lots of better choices.

kaydee123 commented: goood +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use the .is_open() method on lines 16 and 38 rather than fail. Fail is something different like for example if your stream is trying to read in doubles and it encounters a letter in the file (there are other situations that this arises in too). See http://www.cplusplus.com/reference/iostream/ios/fail/

Also, you could just read the data into an array (as long as it's not overwhelmingly huge) and do both of your calculations off that (unless you assignment precludes this).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Law of cosines (http://en.wikipedia.org/wiki/Law_of_cosines) will help you get the angles between all of them.

I would test for the right triangle that way rather than your method (especially since your values a,b,and c are doubles and comparing those for equality is tricky (since a number close enough for practical purposes will not be equal, 1.0001 != 1.0).

If you are going to use that Pythagorean approach some of your formulas are off if a^2+b^2 = c^2 then a^2 = c^2-b^2, etc.

StuXYZ commented: rep. for the double comparison educational outreach +3
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here are a few links:

Specific to what you were looking for:
http://www.stevetrefethen.com/blog/UsingGoogleMapsforGeocodinginC.aspx

Google's reference for geocoding
http://code.google.com/apis/maps/documentation/geocoding/

How to get an account and use the RESTful services
http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_protocol.html

I've used a similar API with Netflix but I haven't used the Google one in particular. Those links should get you started and give you some other search terms to try.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is a good overall reference: http://www.cplusplus.com/reference/string/

Your function would look just like this (omit the std:: if you have a using directive):

std::string enterPass()
{
    std::string pass;
    cin >> pass; //provided no spaces, otherwise use getline
    return pass;
}
in your other function

void Passfunc()
{
   std::string password;
   password = enterPass();

  //etc.

}

You can write a std::string right to another one without using strcpy and you can compare them to each other with != == etc. instead of strcmp.