jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since your numbers are single digits, take in your input as a character and check to see if it's a digit (the isdigit is meant for characters). See if you can rewrite the condition of your while loop to account for numbers in the right range (hint, look at an ASCII table).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where are ReadRec and DisplayRec? You've got the right idea, but .eof() isn't a good idea (see http://www.daniweb.com/forums/post155265-18.html). Post your attempt at those methods and we'll help you with them.

Also, you want if(!infile.is_open()) on line 24. Fail() is for checking if the stream has received "bad" input.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

At least attribute your source: http://www.wsdstaff.net/~dslade/c++WebPage/Ch08/Ch08_Examples/Ch08_Exmp5/MagicSquare.html

(your professor will appreciate it, too)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's definitely generating duplicate pairs and seems to be printing out the last value chosen five times when you ask for it to display the ships.

I'll keep looking it over, but the bugs are subtle. If you can narrow down where it is going awry that would be even better.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

line 106 in battleship.cpp is not correct: if (battleShip.sunk = true) I don't know if that's the problem, but I just noticed it.

Also a quick aside: if(CONDITION) has a condition that is boolean, you don't need to test it versus true or false: if(battleship.sunk == true) is the same thing as if(battleship.sunk)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

... and so what's the difficulty?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

"answer" in battleshipinput.cpp is an int, it should be a char. You were putting in 'y' and the stream went bad so it looped.

For extra credit: see if you can express match() as one line.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

NVM: I found it

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

location possibleLocation; You declare this in deploy() but you never give it a value.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Never used it, can't vouch for it, but take a look at http://www.lumenvox.com/help/speechEngine/index.htm

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Next time please use the code tags to post your code [code]

[/code]

Ok, so what are the issues with it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Rely on the balance you keep within the program. If you wanted to make your code fancier, you could have an option to load the last balance from the register, but I wouldn't worry about that.

For your add_to_balance and subtract_from_balance you want to be operating on the currentBalance variable directly rather than passing it in as a copy. Remember, this currentBalance is a member of your class, it is within the checkbook object. So, add_to_balance shouldn't return anything. Instead you add depositAmount to currentBalance and move on (this way what you have on line 178 will work). I'm not sure what the assignment calls for, but you could also write the transaction to the file at that point.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Skim through http://en.wikipedia.org/wiki/Call_stack (there's a lot of info there but it gives you an idea of where the terminology is coming from. If you try to access an index of an array that is greater than arraysize - 1, you run the risk of trying to access an address that belongs to an adjacent piece of data, which can corrupt the memory.

Like I had mentioned before, if you're having your user enter integers and they enter the letter a, it befuddles the input stream, the stream "fails" and stops taking any more data until you .clear() it.

Using .ignore() will allow you to take in a certain number of characters that the system will throw away. Sometimes when entering data, you get a stray '\n' (newline) in the buffer. If the next command is a cin.get() then the newline will be taken in and the program will effectively skip the pause in your program.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Array should be a pointer to int, because you're going to instantiate it to a certain size in the constructors. As you probably know, your syntax on the constructors is not correct.

Follow the directions:

There should be two constructors:
One that takes no argument creates a Queue object of maxQ=100 values.
One that takes a parameter q and creates a Queue object of maxQ=q values.

Note that maxQ should probably be a private member variable.

If for some reason you are trying to do this class and pick up C++ at the same time, run through some tutorials before you take this on. The time invested now will be returned when you don't have to keep looking up fundamentals.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Which component is giving you the most trouble? The instructions seem to be a good starting point. Try to implement at least some portion of it (class, two constructors, etc.) and post your code and someone will help.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I can show you the code I have so far.

Please do...there's no way to help you without it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please be more specific about the nature of your difficulty. Please post your code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Rather, let your loop check for reaching the end of the words too, rather than '\0' as I said above, as that would halt it prematurely. Play around with the conditions of your for loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 46, the first portion of the for loop statement doesn't do anything, you could move part of line 42 into that position and have for(int StringPointer = 0;WordsToAnalyze[StringPointer] != ' ';++StringPointer) but that StringPointer variable will be destroyed after the loop completes since it's declared locally, so leave 42 right where it is and put for(;WordsToAnalyze[StringPointer] != ' ';++StringPointer) The primary problem is that there is no space after the word "done" so your loop keeps running. Let your condition account for reaching a '\0'.

You should also check in 46 whether you have hit 1000 characters, since if you have already done so, incrementing again will go to array position 1001 which doesn't exist and line 53 will cause an error.

You want cin.ignore(); instead of cin.clear(); . clear is for when you are reading into a stream and you've encountered something unexpected, which makes the stream go "bad."

.

Some random advice:
I have used the CPP Primer Plus in the past and really, really like it. The examples are crystal clear and well-explained. Someone pointed out something important about it, that it starts out as teaching you C and then working your way "up" to C++. This is considered by some to be an older method, not a bad one, but one that doesn't touch on the powerful aspects of C++ right away. I would suggest a book like "Accelerated C++" by Koenig and Moo because it takes such an approach. …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need to mess around with the file read/write for balance at all. Is there any reason why Checkbook can't have a private member variable named balance? Then your balance() and add_to_balance methods really only need 1 line (well, you should do some error checking too, unless you want an account in the red for 10,000.00).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thank you. That is exactly what I was looking for. I tried code::blocks and I like it. Maybe I give a try to Eclipse too. If I would ask you which one is better what would be the answer?

Yes.

I've never tried to use C::B with any other language, but Eclipse has plugins for darn near anything ever thought of in computing's history. I know that C::B has a lot of add-ins, but I have no experience with them. Both have integrated debugging support which is nice. I find Eclipse a bit more bloated and slow, but it's responsive once it fully starts. I'm sure other people will have their own opinions

My program is a graphical simulator under the allegro graphical library. Which one can fit better for the coding?

By the way, as the example with Dev-c++ showed it is important to choose the right tools for programming - what do you think about allegro? It is possible that it is not the best choice for graphics?

Check and see if there's an add-in. I'm not a graphics guy and I'm not really familiar with allegro beyond having played a couple of games that use it for the engine.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Dev is outdated, comes with an older version of gcc, and is no longer in development. Try Code::Blocks it definitely has that feature you are looking for. Eclipse has it too, I believe.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For starters, I would try rewriting it in a more conventional way, you'll probably understand it better. Think about the open square as a line at the top row and bottom row, and one square in the first and one in the last column for all other rows.

This way is not wrong, but one of the tenets of software design is providing the ability for someone else (or yourself!) to read and understand your code later on.

P.S. (and this is not directed at you by any means) I wish comp sci professors would come up with something original, these exercises are tired.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The order you process the numbers in is important, you have to be taking out multiples of the smaller number from the larger one. A few if statements should correct the problem.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I can't directly answer your question, but there are programs available that do similar things like wix (http://wix.sourceforge.net). I've never used it (as usual), but it seems very extensible.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

(In addition to most of the above...)
... I don't know if this was considered before, but how about a 10 second tutorial during registration? You could throw in how to mark the thread as solved, too.

The SEO/marketing people might complain that they don't use code tags, but how many of us have sat through safety meetings for equipment that we might never use.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There must be a critical file missing from your install. Can you try reinstalling it?

Really you're probably much better off getting MingW (the windows port of gcc) with Code::Blocks) or one of the Visual C++ Express Editions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, probably best to start a whole new project in VS 2010 and copy/paste the code into it. Make sure precompiled headers are off.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

But the thing is if i can do it in java i can do it in C and C++

Have a go at it and we'll help you. Some folks speak Java, but it's been a while for others. Rather than take up the time of someone in the Java forum to help you write the code and then someone in the C++ forum to help translate it, try it in C++.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you open your code in VS 2010 and it was created in VS 2008? That was what I found for the assertion error. You need to import your project so it is not dependent on the old DLLs.

As far as the other functions go, please take a crack at them first and we can help you with whatever issues come up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

"nod" is declared in your constructor which means it is a local variable, and is destroyed once the constructor completes. Declare "nod" as a private member variable, and then you can initialize it in the constructor as you have.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Iam using gcc compiler: gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5). And it allows me to use such things. Ok. i'll try now to use a constant.

Edit: tryed a constant - same sh**. Am, and have you noticed, that it is not the function which causes problems ? with this function everything is ok.

See my edit above. I don't want to speak for him, but I don't think that AD was saying this was the cause of the problem, but he was offering you some advice on your code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For line 140, you want is_open() for sure.

EDIT: Also, the g in seekg is for "get pointer," which belongs with ifstream only. The corresponding functions end in p for the ofstream. (see http://www.cplusplus.com/reference/iostream/ofstream/ midpage).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try Googling those terms. It's been a while since you've posted, but I remember you were going through similar things before. Find the simplest example that does what you want and emulate it in a short test program (3-5 lines) and then integrate it into your work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you make a loop that will count 1, 3, 5, etc.? Use that. I'm not sure what the e means either. Do you have an actual value for s? Perhaps you are supposed to stop adding terms when you are within 0.1 of the value of s.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure I understand what you are trying to accomplish. You're reading in the names as std::strings into Name, but then you don't do anything else with it. You've got a colon after Name on line 29, so that's probably why it's getting stuck (colons can indicate a label in your program), but I'm not confident of how it compiled.

I think your typedef just makes everything more confusing, but that's a matter of opinion and style.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

inttobin is spelled incorrectly on line 25.

Remove line 72, the redeclaration of n is masking your function parameter n.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

One way to do it would be to go through your seating chart and use the price for each row to get a total.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Nope. Nothing.

Now that I look over something, could it be because I'm setting the value of E, then RIGHT after I use the value?


Edit:
Ran it in Debug mode and I got an error segmentation fault
Checked it out, program points to a line where the E value is used in a loop. If this value is anything less or more then whats in another file Im reading, theres problems.
So What I said above could be it?

But still why it accepts 8 and lower but nothing else :/

I was trying to show that the file read works fine in isolation, so it is definitely somewhere else in your program. Since I cannot see the rest of your program it is difficult to gauge. Test your file reading routine on the other file and see if it's general enough.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's an example of one in C++/CLI (so if you were to create a WinForms application in VC++) http://www.speakcomputers.com/Windows-Forms-Programming/C-PlusPlus/TreeView.aspx

Otherwise, you need to come to us with something, as there are a bunch of tutorials out there. Make some decisions about your implementation at least (e.g. Win32 API vs. .NET vs. another windowing library like Qt).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try the following program. Note the warning about global variables.

#include <iostream>
#include <fstream>

int M = 0,T=0,W=0,H=0,L=0,Start=0,Startx=0,E=0;
//Global variables should be avoided! but I'm trying to emulate your program

int main()
{
     std::ifstream load("ifstreamcrash.txt");
	
     if (load != NULL) {  //use .is_open() method instead
        load >> M;
	std::cout<<"M= "<<M<<std::endl;
		
        load >> T;
	std::cout<<"T= "<<T<<std::endl;
        
        load >> W;
        
        load >> H;
        
        load >> Start;
        
        load >> Startx;
        
        load >> E;       
	std::cout<<"E = "<<E<<std::endl;
		
	} //I didn't close the stream because the program ends here, otherwise you're right
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Plan out what you need to do on paper first. As a start, you should be taking care of part 2 all at the same time instead of in a separate loop.

March along your num array, when you come upon a number, see if it's in dist, if not add it, and continue along num, incrementing a counter as you go. Enter that counter into the respective spot in the ctr array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where are M,T,W,H, etc. declared, and what are their types?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
000000000111111111122222222223
      123456789012345678901234567890
Row  1
Row  2
Row  3
...
Row 10
Row 11

This way one seat number sits over one seat position and the rows are kept neatly in line.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Both find() and size() return an item of datatype "size_t," which means what it actually returns is defined from system to system, but normally is an unsigned int. Make i and pos of type size_t.

For next time, please list what the warning is so someone doesn't have to guess.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i have everything fixed now except the allignment of the chart and "view seat sales" option which doesnt seem to work

I've told you how to handle the alignment in a prior post, and how is view seat sales supposed to work when there is just a stub there?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look at lines 131-133, there is no code there. If you are saying that is the functionality missing in your program, get these portions working first.

Put some cout statements in your program for debugging the freezing (or use a debugger). Try to isolate the line that it is freezing on (so putting in statements like "Checkpoint 3" or whatever you like after it's made so much progress). I can't reproduce the problem so I won't be much help.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
MAIN MENU
 1. View Seat Prices.
 2. Purchase a Ticket.
 3. View Available Seats.
 4. View Ticket Sales.
 5. Quit the program.
_____________________

Please enter your choice: 3


View Available Seats

        Seats
   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 30

Row 1 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 2 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 3 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 4 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 5 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 6 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 7 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 8 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 9 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 10 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 11 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 13 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 14 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 15 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #


        MAIN MENU
 1. View Seat Prices.
 2. Purchase a Ticket.
 3. View Available Seats.
 4. View Ticket Sales.
 5. Quit the program.
_____________________

Please enter your choice: 2


Purchase a Ticket

Please select the row you would like to sit in: 4
Please select the seat you would like to sit in: 19
That ticket costs: 42
Confirm Purchase? Enter (1 = YES / 2 = NO)1
Your ticket purchase has been confirmed.
Would you like to look at another seat?(1 = YES / 2 = NO)1
Please select the row you would like to sit in:

I can't reproduce it unless I put in a letter instead of 1 or 2... Have you changed your code since the last time you posted it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think what you want to be doing, if you are going to use that approach with shifting, is making all of your arrays the same size as the largest one. Say your largest array is 20 and someone enters 4 digits, you need to shift index 3 down to index 19, 2 down to index 18, 1 down to index 17, 0 down to index 16. I'm sure you see the pattern.

If your sum going into the leftmost number is greater than 10, you have overflowed your capacity. So, for the sum make the array 1 longer than the longest item.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I compiled the code that you put up:

MAIN MENU
 1. View Seat Prices.
 2. Purchase a Ticket.
 3. View Available Seats.
 4. View Ticket Sales.
 5. Quit the program.
_____________________

Please enter your choice: 2


Purchase a Ticket

Please select the row you would like to sit in: 2
Please select the seat you would like to sit in: 5
That ticket costs: 30
Confirm Purchase? Enter (1 = YES / 2 = NO)1
Your ticket purchase has been confirmed.
Would you like to look at another seat?(1 = YES / 2 = NO)1
Please select the row you would like to sit in:

That's just one run, but I did try it repeatedly last night. What is the exact sequence that you used to get to that point?