jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Usually anything with Try in front of it in C# checks to see if the retrieval/conversion/etc. is valid so you can use the call in an if statement.

Since the bool is returned, the value is returned by reference in the second parameter (C# has the designation of "out" to indicate that the parameter will be given a value within the method call). You can modify ravenous's code slightly to attain the same features.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you are on a different platform than he is (Linux vs. Windows) you're going to have to compile his code on a Windows machine. He could conceivably generate a Windows binary, but it's not the default and it's probably too much trouble at this point. have him send you the .c file. As long as there's all standard functions it should compile on both platforms.

EDIT: Vernon beat me to it. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On the left hand side of your post (the post in question, not this one), underneath your name, hit the "Flag Bad Post" button and explain your situation to a moderator.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I won't send you a program. It's against the forum rules, and besides, this is your assignment.

Now, so you've got a good start with getline. After you've read in a line, check it to see if the string you are looking for is contained in it. If not, immediately write the line out to the file. If so, modify the line and write it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you read the values in and write them back out again? Start there if you can't.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Some think that it translates from the ancient phrase meaning "for the love of all things good, get a book on C!"


(and before you judge Jonsca, this is the 4th (my fact checkers say) such request from this OP)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

To my knowledge, you won't be able to do that. Two things I could think of would be, depending on the range of your valid numbers, use a sentinel value (so if your data are guaranteed to go from -100 to 100 use -999 or 999). Another possibility would be to have a parallel array of boolean values. If there's a value in a slot of the numeric array, set the slot in the boolean array corresponding to it to true.

Again, someone may have a solution that's simpler or more effective, so stay tuned.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It might be helpful if you gave a brief snippet of what you are trying to do.

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

If you are using C++/CLI like you were, a String ^ has an identical ->Split method to the one in C# (since it's all .NET). I think it requires a cli::array<String ^> to accept the pieces.

I suppose you could use a stringstream, but you'd have to convert your String ^ to a std::string by marshaling.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Man, I'm sorry but, do you really expect us to answer your question?

The poster has not explicitly specified that he/she is using C++/CLI and .NET, but this is a perfectly understandable question. It's good that you're concerned about post quality, though.

@OP: Set pictureBox1->BackgroundImage = nullptr;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It is always int, according to the standard.

Again, I wasn't trying to be so harsh, but typing in "int main versus void main" in google popped that answer up right away. It's great to ask questions and I'm by no means discouraging you from doing that, but google it first and see if you get an immediate answer.

that Narue has written

She's darn near always right!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This post will show you how to overload the get method of the property (you may know, but I wasn't sure where to cram all of the keywords in hehe)

http://www.windowsdevelop.com/windows-forms-general/overriding-createparams-in-derived-form-59363.shtml

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

http://www.eskimo.com/~scs/readings/voidmain.960823.html

Did you try Googling it at all? (I say this not trying to be a jerk, but you've had 4-5 questions that are things that could be easily answered on Google)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have to translate this code from nobugz in this post from C# into C++/CLI http://social.msdn.microsoft.com/forums/en-US/winforms/thread/60b2493d-c8ff-495d-b845-d114fe456f54/ I'm taking a shot at it, but see what you can come up with from there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's nothing technically wrong with using printf, but there are ways to accomplish the same thing using cout.
In particular, look at the examples:
http://www.cplusplus.com/reference/iostream/manipulators/fixed/
http://www.cplusplus.com/reference/iostream/manipulators/setprecision/

It looks to me like your assignment is saying all you need to do is output the number of each of the bills and coins. I would do just that:
cout <<"Twenties - "<<i/2000<<endl; instead of line 18.

If you think your instructor really wants all of those variables coming back to main, then pass them in by reference (with the &)
void denomination(double change, int & twenties, etc.)

If you trace your function through by hand, you'll see that all you'd end up returning each time was 0 (since your leftovers after the pennies will always be 0). Also, if you want your function to return an int, don't make it double and then cast that to an int back in main, just return the int!

Watch the pennies too, there's a round off error happening when you're casting change*100 to an int.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if (x == 'y' || 'Y')

is not correct

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

is. The first one is taking the OR of what amounts to two true entities (since 'y' and 'Y' are non-zero values) and comparing that to x. Same for the 'N' scenario.

You should change your goto statement construct into a do/while loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm sure it's possible, but I'm not sure how you would implement it (aside from the idea that it probably requires using Win32 API).

If you're looking for the ability to interact with webpages you can do it somewhat more directly with something like libcurl via "GET"/"POST" commands.

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

Is it project Euler? If it is, then there are usually some clever manipulations you can pull and the bottom falls out of the whole thing and you're left with the answer. I haven't made it very far through them, but some people around have.

I don't have any real experience with Diophantine Equations, so I couldn't tell you...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The easiest solution is to use the library that I gave, but if this is an assignment you need to do some variant on what I suggested above. Does it seem likely that this would be your instructors objective?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Some of the banned users still seem to appear in the "Currently Online" and move up the activity points chart. Is it that they never logged off?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Not supported under standard C++

error: ISO C++ does not support `long long'

I tried it with __int64 which is I believe is normally a Windows thing, but I think that the compiler substitutes long long for it.

I'm fairly certain the instructor is going for the array representation.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're going to have to use either a char or an int array to hold the numbers.

ex 1234  =>  |1|2|3|4|

You'll have to write a procedure to do the multiplication and division digit by digit

Or if you can use a library, there's GMP or MPIR if you're using windows without cygwin

As a 2 minute exercise for your own benefit, find the largest values of a signed int and unsigned int (or look it up on wikipedia), you'll see these numbers are way over it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

a nice green blocky of +rep

I miss the green blockies...

I said this in A51 but it's worth mentioning again that I have yet to encounter any of this nefariousness, so yizzles are doing a kick-azz job with it. Anytime I've spotted anything on the activity points radar (and I check because I've been edged out by that Adatapost fellow, curses) the parties have already been banned.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you google "SMTP C++" you get some hits, but I don't know if any of them are any good.

Have a look at this thread: http://stackoverflow.com/questions/58210/c-smtp-example
It gives you some of the nitty-gritty and some possibilities.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Much better. Note my comments below in the code you just posted.

#include <cstdio>  //don't really need this, no functions were used from it
#include <cstdlib> //same here
#include <iostream>

using namespace std;


void digits(int nvalue) //this is correct

{
    int i;

    for(i=0; i<10; i++) //you don't really need the loop unless you want to do it 10 times
    {

    cin >> nvalue; // delete this if you're passing the value in, don't take in another one

	switch(nvalue)
        {
            case 1:
            cout << "one";  //good, the instructions say no endl after
            break;

            case 2:
            cout << "two";
            break;

            case 3:
            cout << "three";
            break;

            case 4:
            cout << "four";
            break;

            case 5:
            cout << "five";
            break;

            case 6:
            cout << "six";
            break;

            case 7:
            cout << "seven";
            break;

            case 8:
            cout << "eight";
            break;

            case 9:
            cout << "nine";
            break;

            default:

            cout << "digit error\n";
        }
    }
    return;  //when void functions reach the end, they return automatically
}


int main(int nNumberofArgs, char* pszArgs[])

{
    int nvalue;

    cout << "Enter a number 1 to 9: "; //put the cin >> nvalue; after this statement and before the next
    digits(nvalue); //otherwise you're passing in garbage here since nvalue is not
                      //initialized



    system("pause");
    return 0;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So per the assignment, your function should return nothing and therefore be void. You are still not getting that you need a parameter for your function. Look for an example in your text that takes an int. Where is the int in your function definition? Forget about the contents of the function for now, just set up the skeleton of it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you do it without MPI? Try that first.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Getting closer. Line 8 is better, but you still need an integer parameter. I would revert line 19 back to being an int so you can pass it into your function.

A function definition looks like:

[I]Returnvalue[/I] functioname([I]datatyp[/I]e parameter1,[I]datatype[/I] parameter2, etc) { }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since your numbers are integers, you need an integer parameter for your function. Have it return a std::string.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Standard C++ or C++/CLI?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a substring (2 characters) of the string you read in using getline, and compare it to "--" (unless you think your professor will put in aberrant lines to test your program. Or if you know the number of dashes ahead of time, compare it with that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would use getline() to read in each line as a std::string. When it comes to those lines which are variable, read the string into a stringstream and use the >> extraction operator to pull out what you need.

That way you can compare each line with "----------" to see when to stop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't know what it is then. See what happens once you've corrected the other errors.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Move your brace from line 18 (in the last listing you posted) up to line 9, I think you wanted to close the if statement there.

Delete the one on line 19. The brace on line 32 marks the end of the class. Verify all of your pairs in between the opening one at the top of the class and that one on 32 and make sure they match up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So, your WaveMachine.cpp file should look something like this:

// WaveMachine.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace WaveMachine; //is this line intact?

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());
	return 0;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

As Narue was explaining:


They are not within the play button :

private: System::Void playBtn_Click(System::Object^  sender, System::EventArgs^  e) 
		 {

			
			 // Tian: for this example, I restrict the selection and playing of one track only. You can make it more flexible
		 	 if(this->listView1->CheckedItems->Count != 1) {
				 MessageBox::Show("Please check one of tracks from the list below to play!");
				 return;
			
			 //axWindowsMediaPlayer1->Ctlcontrols->next();
			 int random;
				Random^ rand;
				rand = gcnew Random();
				int count = axWindowsMediaPlayer1->mediaCollection->getAll()->count;
				random = rand->Next(count);
				axWindowsMediaPlayer1->currentMedia = axWindowsMediaPlayer1->mediaCollection->getAll()->Item[random];
				axWindowsMediaPlayer1->Ctlcontrols->play();
		         } //IF ENDS HERE
	        } //System::Void playBtn_Click ENDS HERE

//Everything below here is [B]outside[/B] of the playBtn_Click method (where it should not be)			 

// the actual music file and its path is kept in the second subItem (of each track)
			 String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

			 // using soundplayer class to play the sound
			 // note that it can play .wav sound only, and this .wav file must be in PCM (pulse-code modulation) or exception will occur
			 // for this assignment, you may want to choose some of .wav music track to demonstrate 
			SoundPlayer^ player = gcnew SoundPlayer();
			player->SoundLocation = filePath;
			player->Play();

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

Which other errors?

There is no form1.cpp (unless you specifically created a file with that title), so that shouldn't matter.

The IDE should have autogenerated the code you posted above, that's why having the .h there was suspect.

There should be a line in your form1.h that says something like public ref class Form1 : public System::Windows::Forms::Form Check and make sure it says Form1 there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post some of the surrounding code for this one. You're trying to initialize something within a class declaration or struct.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you rename your Form1 class something else?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take out the .h, that's the filename, you want to instantiate an object of type Form1. Application::Run(gcnew Form1());

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I had tried it one time with the C# syntax (foreach) and with the way Boost does it (for_each). I should have pressed on further with it. Apologies to the OP, and thanks to Narue.

(I didn't know that VC++ had a compiler extension for it even for STL containers, either)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to either explicitly have a using statement for System::Collections::Generic or qualify it as Generic::IEnumberable<Item ^> You're not going to be able to use a std::vector without a lot of hassles. Change it to the cli::array that it's asking for. Google for the syntax.

Also, I don't know why you're using auto all over the place. It should be the default storage class as it is in standard C++.

I don't believe the for each (idiom?) exists in C++/CLI. Just loop over the index.

If you working in VC++ 2010, there is terrible intellisense support for C++/CLI. If you have to, develop your projects in 2008 and import them into 2010 if you need .NET 4.0. That way you can hunt through the namespaces if you absolutely need to (which would have helped with the IEnumerable bit).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

CodeBase seems to return the path in a file:///C:\etc\etc format, so you may need to do some string operations on it. I'm not sure why you are comparing the filename to the one on the console, as they are probably derived from the same source.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This should give you the information that you need: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx (scroll down to the example)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 79 of your first listing you have a semicolon after the if statement.

Also, remember than in C++/CLI the . operator of C# can translate to a namespace or a member function. (so either a :: or a -> or even a . for a non-pointer)

But, AD is right in that you need to find the equivalent for a console application (I'm not sure if selecting CLR console will allow you to access the System::Windows::Forms members, but there should be an alternative).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I wouldn't modify any of the headers like that, but okay.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check and make sure he has the redistributables (e.g., http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84&displaylang=en). He may also need the 2005 or 2008 ones for any older dlls, check and see if the 2010 ones supersede those in the 2005 and 2008 redistributables.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

At least post the order of your headers at the top of your code. Is a header you wrote listed ahead of some of the standard ones? If so, you may be missing a ; after one of your class declarations.