jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

amirite?

No, because you're not always going to have someone to take you through a project step by step before you have to do it. You likely have a textbook and certainly have the internet if you don't know how to do something.

No one is going to give you code without you showing some effort first. If it's object oriented, start by creating an Account class and I'm sure you can get a general skeleton going for your menu system in main.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I hate to tell you this, but you're going to have to narrow the code down dramatically and present questions about specific sections because someone is not going to go through and check all those steps for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure what to tell you, this is one of those things that is difficult to diagnose, as it's some setting that you are selecting. Zip up and attach the directory of the project to your post.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See the example on the bottom of this page http://www.cplusplus.com/reference/stl/vector/erase/. You'll have to add an offset to .begin() to index in. So to erase the 6th element vectorGameList.erase(vectorGameList.begin()+5);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i suspected it did not produce the warning you are seeing,...

I would say try starting a new project and copy your files into it (or you could try turning off multibyte characters under Project/<Projectname> Properties/Configuration Properties/Character Set and setting it back to Unicode, but I'm not sure if that will work).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, cout can handle C-strings okay. Hmm, when I compiled and ran it, it had no problem (though I didn't try it in Visual C++). What parameters are you giving your executable, and are you putting them in at the command line directly or via the arguments option in VC++?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Allocates room for a C-string in pFilename that's the length of argv[1] and room for the null character. Then it copies argv[1] to pFilename.

Is the above the exact code that you are using. If it isn't post exactly what you are running now.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Because argv is a C-string, you have to use the methods in <cstring> (such as strcpy, strcmp)


char * pFilename = new char[strlen(argv[1])+1]; //room for null terminus '\0'
strcpy(pFilename,argv[1]);
//accomplishes what line 23 does
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's not lame, everyone is still learning something or other... :)

Lists are not too hard to add to your repertoire, and they are very useful when you don't know how many items you have.

List<string> sl = new List<string>();
sl.Add("first");
sl.Add("second");
sl.Add("third");

//sl[0] gives you "first"
//sl[1] gives you "second"
//sl[2] gives you "third"

You can make a list of your structs,too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

gcc refers to the GNU compiler collection (it's also the command to invoke the C compiler, which makes it a bit confusing).

Glad you got it working! (look into some of the other switches available with that compiler, particularly -Wall to have it display the highest level of warnings.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

- Compiling in Terminal

What is the command you are using to compile? You need to put both .cpp files in the command. g++ myclass.cpp mymain.cpp -o myprogram (assuming you're using gcc).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just to throw this out there: what if you read all the data for one car into a List<string> and added that to a List<List<string>>?

Add the first member of each list (the VIN) to the combobox, then use the SelectedIndex of the combobox as your index into the List<List<>> and display the make, model, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It has to evaluate foo() in the second case because if foo conceivably returns 0, then the second operand will have to be evaluated. I don't know if the compiler can think three steps ahead to know that that is not possible based on the values, but that might be asking a lot.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is a good thread on SO about it: http://stackoverflow.com/questions/628526/is-short-circuiting-boolean-operators-mandated-in-c-c-and-evaluation-order

Both are short circuiting, so since your first operand of || was true, it skipped the foo() call in the first example.

VernonDozier commented: Good link. +13
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are simply outputting your variable total (which hasn't been changed from when you initialized it) plus the ticket price. You need something like total+=ticketprice; . You want to do this if the seat is not reserved, so you can put it under an else branch of your if(s1==reserved) block (obviously, do the same for s2 and s3).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you have set the image as a PictureBox Image using the properties window, you just change the image in your MouseEnter handler. You'll need a MouseLeave handler setting the picture back to what it was if you want that effect.

In the MouseEnter: yourPictureBoxNameHere->Image = Image::FromFile(YourNewImagePathString); In the MouseLeave: yourPictureBoxNameHere->Image = Image::FromFile(YourOriginalImagePathString); I'm not sure what the big deal was, you were 3/4 of the way there. I was suggesting you use the BackgroundImage property (which can be set in the Properties window just like the Image property can) because there's more control over how the image is placed. I did it your way with the Image and the picturebox came out scaled funny (I'm sure there's a way to change this with Image, but I was offering you a suggestion I was familiar with).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Keep a running total in a double variable. Add the ticket price into that total within each of the cases of the switch statement, like right after you set the seat to reserved (note that you want to make sure that you're only charging once per ticket).

In other words, add a else if condition to your if statement that says if the seat is unreserved, reserve it, and then add the price into the total.

Give that a try and post back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, it certainly requires code to change the picture. Did you put the picture in through the properties window on the right side of the IDE?

I think you're misinterpreting background image here. I'm not talking about the Windows background, I'm talking about the image that is displayed in the picture box. I've never had any luck using the PictureBox.Image in this fashion, that's why I'm recommending setting and changing the backgroundimage of the picturebox, not whatever you have for the background of your application or the Windows background.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Through what method have you placed the image in the picturebox? Show the code that you use to initialize it. I have found it is easiest to set the image as "BackgroundImage" of the picturebox and then change it by replacing that BackgroundImage with a new one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

the choice is declare as int...

choice is character

I said choice should be a character. In the OP's code it is not.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's the property of the PictureBox that you want to change. How have you set the image on the picturebox thusfar? Please read the link that I gave you or find a suitable tutorial on the subject.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

He's using .NET (C++/CLI). OP, you should specify this (at least that you are using a Winforms project).

MSDN has great pages on all of the controls. You'll find that you need to change the BackgroundImage (and probably the BackgroundImageLayout). http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox(v=VS.100).aspx

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If there are less than 10 choices, take in the choice as a character rather than an integer. Check to make sure the character is between '1' and '9' (or '0' and '9' if you want a choice 0).

Alternatively, if a 2+ digit answer is required, take in the input as a string and check each character to see if it's a digit (using the functions in <cctype> if permitted or the approach above if it's not).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're making life difficult on yourself:
Define a variable max, set it equal to the first element of the array
Step through the array, if the current element in the array is greater than max, let max be equal to that element, and set temp = index. Only change the index if you find a new max.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See my edits in the last post.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Substitute the line that I wrote into your code sample on line 4. If you do that, does it still give you an error? There's not that much more to it.

Not trying to be mean here, I guess I don't know what else you need to see.

BTW, if I don't mention it, someone else will, but some compilers do allow you to declare arrays with a variable size like you did, but it's an extension to the language and therefore non-standard (so probably not recommended).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not as familiar with strtok, but you should try passing in line.c_str() to it instead of the address of the first character on line 14. What you did assumes something about the implementation of the std::string which may not be true.

Either way, you seem to be getting a null pointer being passed into isValid. Output the value of inst after line 14 to see what's in there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, you would want a dynamic allocation. In C++, a fixed-size array's size must be a constant known known at compile time.

You need int * myarray = new int[sizeofarray]; Since the array is dynamically allocated with new, you need to delete it to free up the memory, delete [] myarray;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Rather than have a global ifstream object, declare it in main() and pass it around by reference.

In your ReadLine function, what happens if your line doesn't contain any of those characters? If the function is not void, it's good practice to have a return for all possible paths through the function.

None of these problems should lead to a crash, though. It is more than likely something else. How did you determine that the function you posted was crashing the program?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where is "file" coming from in your listing in the OP?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

5/9 is an integer division, which gives the value of 0. Change one or both of them to have a decimal (5.0/9, 5/9.0, or 5.0/9.0) which will perform the calculation with doubles.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change fee to be of type double (it will fit in a float, but live large, j/k). You'll need to change total also, otherwise whatever you add to it will be truncated.

Like Momerath said, the division of two integers will be an integer, so 4/100 = 0 (and 101/100 is 1, since there is no decimal). Change 4 to 4.0 or cast it to a double.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, the only way to get it is through the full version of VS. The Win32 API is available on the Express Editions (along with .NET).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to add the \bin directory of the mingw folder to your path. Ex: http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx for Windows 7.

Another thing you can do is make a shortcut to a cmd window that runs a batch file that sets the path for that window only:
(call it mingw.bat or something)

@echo off

set PATH=%PATH%;C:\yourmingwpathhere\bin
set PATH=%PATH%;%SystemRoot%\System32

Then, create a shortcut (right click on the desktop, new, shortcut) and put %COMSPEC% /k c:\yourbatchfilepath\mingw.bat (change the Start in: directory to wherever your code is, so it goes to that directory each time).

Then, once you have your file above saved as native.cpp (or something) invoke the compiler by typing g++ native.cpp -o yourexecname

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Which compiler do you have installed?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're not calling your functions anywhere within main(). It's simply outputting your input all in a row, as that's all you've asked it to do.

You need to name your functions better. Ave is finding a sum, and out is finding the average. That's confusing to anyone trying to read your code (especially your professor).

Your other functions operate on doubles. Since S1,S2,S3 are being passed in as integers in the "out" function, if you pass in a double value, it's going to be truncated down to an integer, so 16.4 would become 16, etc. To make matters worse, on line 42, you're summing 3 integers and dividing by an integer, which no matter what type "Grade" is, you'll get an integer response. So for S1+S2+S3 < 300, you'll get zero for a grade.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Show the line(s) that you are using to put it into the text file. You may be adding endl to the end of the line when you don't want to. If you're then, reading it back into a string, something like getline reads to the end of the line and discards the newline character.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 56, rename posi to posi_short or something, as it's overwriting the value of posi that you found for the longest word in the previous for loop.

I was just saying that you don't need a second for loop to test for the shortest value:

for( )
{
   if(count is longer than longest)
   {
        longest = count;
        posi = i;
   }

   if(count is less than shortest)
   { 
        shortest = count;
        posi_short = i;
   }

}

Save yourself from making two passes over the data.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Think about it, you can find the shortest and the longest all in one pass. Name your variable that marks the position of the shortest word as something different so it doesn't overwrite the one for the longest word.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

By doing something similar to what you did for the longest word?

if(count < shortest_word)
{    
    shortest_word = count;
    short_posi  = i;
}

Start longest and shortest initially as the length of the first word. If you have shortest_count = 1 then it's going to be tough to find something shorter than that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, you'll need a while loop and the >> operator.

std::string tempstring;
while(ifs >> tempstring)
   Add tempstring to vector

Play around with that with different text in your file, like

"Does it tellthewords apart what happens      if there's a big space, or punctuation!"
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Based on what arkoenig has told you, you could read in the words one by one into a vector, as the extraction operator(>>) is delimited on space (probably would have to get rid of punctuation first). That way you wouldn't have to keep track of spaces at all. You'd just end up with a vector full of words and you could perform whatever manipulations you needed to process them.

Not sure what'd you'd need a struct for in that mix.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You've used vectors in your other threads. Think about things you could do towards this problem with a vector of strings (or even an array of strings, if you wanted to practice those).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay, so trace through that sample file with a pencil and paper. Where are the capital letters necessary? What separates the sentences from each other?

Once I hit the period, there is a ________ or a _________. After that, if there is a letter, capitalize it.

Now translate that into code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The specification says that the sentences are separated by periods. I'm assuming there won't be a space after the period. Keep track of the last character you read, if it's a period, capitalize the next letter. If there is a space, you'll need to skip over it before capitalizing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's my understanding that it's a perfectly viable option to use a native C++ DLL with an interface designed in C#. I'd say go for it. It's not a problem that you're noobish.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So that event handler isn't firing at all. Go through the code and check all of the event handler hookups this->systemBOX->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox1_SelectedIndexChanged); as this particular one is hooked up wrong.

What is comboBox1? You want systemBOX's SelectedIndexChanged event to be associated with systemBOX_SelectedIndexChanged (the event handler you have in your last post) not comboBox1_SelectedIndexChanged.

I'm happy to help you, but you've got to keep track of your own code, and if you don't understand the mechanics of these things you'll have to do some reading on them, or at least rely on the IDE to put them in the right spot for you.

You were asking about sites before, the functionx.com site is decent, but it's definitely the most comprehensive out there (http://www.functionx.com/vccli/index.htm)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Within that same event handler, put in

MessageBox::Show(systemBOX->SelectedItem->ToString());

and see if the messagebox pops up with the string, to make sure the event is firing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

toString

It's ToString() (case counts). The intellisense in 2008 is nice, as you can just type your object's name and then the -> and it drops down a little menu to select from. There's some in 2010, but I don't think it works for everything.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is your ComboBox called? If that's not the right name, change it to whatever it is named on your form. In fact, probably should erase that event handler code and let the IDE regenerate it for you. Double click on the combobox on the form and the proper handler will be placed in the code automatically. Then, use the SelectedItem of that combobox and it's ToString() method.

Just a suggestion, but if you don't need .NET 4.0 stuff, you can get away with using VC++ 2008 Express Edition, which has much better intellisense for C++/CLI than 2010 does (shows you their priorities).