1,608 Posted Topics
Re: Use pencil and paper. I think you'll find you need to use 4 pointers, current, and a temorary node. Insert after current: temp = current->next; //keep track of this value //attach newInsert after current current->next = newInsert; newInsert->previous = current; //attach whatever current used to point to after newInsert newInsert->next … | |
Re: It probably has to do with the implementation of unget(), though since I don't know how unget() is implemented I don't know that for sure. Having said that, if unget() puts the last value of ch back in the input buffer, but doesn't take the last value of ch out … | |
Re: You can't compare char arrays using the == or the != operators and you can't compare C style strings (null terminated char arrays) using those operators either. To compare char arrays you need to use a loop and compare each char in each array one by one. To compare C … | |
Re: Place all the code you want to repeat each time new stuff is read from the file inside the body of a loop, maybe lines 34 through 76, or something like that. Use line 35 as the controlling condition for the loop to run by placing it between the parenthesis … | |
Re: All line numbers refer to post #4. Bigint::Bigint() Is the default constructor. I'd use it to to set num to be an empty string. Line 63 is an example of how to do that. As it stands now:[code] Bigint::Bigint(string str){ for(int i = 0; i < str.length(); i++) { num.push_back((str[i]));[/code] … | |
Re: You want to stop when n == end, not when n == start. The first value of n is start and you should never get back there again, if you aren't going to visit any vertex more than once. Try changing line 21 to printPathHelper(g, end, start); Change parameters in … | |
Re: Assuming the lines of the files are all in the same format as the two posted you can use getline() with comma as the delimiter to read the first part of the line and then another call to getline(), or a call to >> to read in the numeral. Beware, … | |
Re: If the polynomial is restricted to a single variable polynomial then each node needs to have a coefficient and an exponent. You can recieve user input for each, individually or you can accept the full polynomial from the user as a string and break it down term by term until … | |
Re: I think the problem is on line 93: getline(cin,newquestion,'\n'); Fair enough, but in addition to pointing to where you think the problem is it also helps to explain the problem. I will assume the problem is that the code isn't putting information into newquestion. If that's correct, then the problem … | |
Re: option 1: Each time you want to add a new column to the left hand side of the matrix declare a new, bigger matrix using dynamic memory, then load the data from the vector in the first column using a loop, followed by another loop transfer the data from old … | |
Re: 1) This is called edge detection which is often part of a validation process. If the x or y coordinate is above 17 or under 0 then that move is invalid so you can tell the user and ask for alternate input. Keep doing that in a loop until a … | |
Re: Three thoughts. You might look up the ctime header file and see if there is a standard way to do what you want. Otherwise you can develop your own functions to do what you want. I don't think there is anything in iomanip that help you, but you could check … | |
Re: These are the first lines of the function definitions: double calculateGrade(grade) int enterTotalQuestions(tot_quest) In the above, grade and tot_quest need to be preceded by whatever type they are. Since you define calculateGrade() and enterTotalQuestions() before main() instead of after, then the following lines can be deleted. double calculateGrade(double); int enterTotalQuestions(int); … | |
Re: try declaring an empty STL style string. The concatenated each char to the end of the string. Store each string in an array and sort the array after input stops. | |
Re: First, learn to use code tags when posting code to this board. It's not hard and it will preserve the indentation you hopefully have in the original code making it easier to read. Glancing through your code it looks like you've managed to use a stack. a queue and a … | |
Re: Matrix2d<int> mat; aMat.sizeMatrix2d(xA, yA) Line one above does indeed call your default instructor. In your default constructor you initialize rows and cols to zero and matrix to NULL. There is no memory declared there. Without seeing sizeMatrix2d() there is no way to know if there is a problem there or … | |
Re: [code]in main { create board and intialize to E declare plays and initialize to 1 declare no Winner and initialze to true while(plays < 9 && no Winner) { make play ++plays winner = win() if(winner != 'C') no Winner is false } if plays == 10 draw else if … | |
Re: Always start with a plan on paper that you write out with pen/pencil. For example, in this case you might try something like this: Determine mazeHeight Determine mazeWidth Use an array of type char to represent the removeable walls. Using dynamic memory and the formulas you described declare the memory … | |
Re: >>one person i talked to mentioned read the file as strings and tokenize the data is this a good way to do it? If the file is ordered as posted it wouldn't be that hard to create a class modeled around the information for each customer and to create a … | |
Re: Try this:[code] //if any of the remaining coefficients is more than zero, then print out "+" for(int j = n-1; j > 0; --j) if(p.coefficient[j] > 0) cout << "+";[/code] Assuming degree is the largest exponent in the polynomial associated with a nonzero coeffieient then the degree of the product … | |
Re: line 0 has 1 star line 1 has 3 stars line 2 has 5 stars line 3 has 7 stars Without looking at the program how many stars does line 4 have? How many stars, call that number y, would line x have? Now try to write down on paper … | |
Re: The math is square foot per room times 1 gallon of paint per 500 square feet. Then round that up to next int, which represents the number of gallons of paint to buy. Then multiply that int by cost of paint per gallon. Rounding up in C++ can be fun. … | |
Re: >>i want this program to find a name after i enter it. here r the names that i want to put into names.dat. Alternatively, create a section of your program to write whatever information you want to the desired file before you download the file back to your program. Not … | |
Re: If you want to get the most "reuse" possible out of the struct you could put it in a header file by itself coupling it with an empty cpp file with the same name as the header file, but since the struct is so straightforward leaving it like it is … | |
Re: >>I'm trying to increase the size of the array I'm confused with all the len, length(), pos stuff. Basically if array a is too small and you want to enlarge it, then you can copy the contents to a second array, temp, delete a, redeclare a with additional memory than … | |
Re: If you wrote it presumably you know what's going on, or what you want to have happen, and might not be. If you have a specific question post it. As it stands there is plenty of questions you could be asking. I would prefer not to step in and tackle … | |
Re: Welcome to the board. Please read about using code tags when posting code to this board so that you syntax formatting is maintained. The information you need is in both the announcement section and the read me before posting post at the top of the board. The function getElements() will … | |
Re: Change the extraction function to take a reference to an int as an argument and return an int. Extract just the least significant digit from the number passed and return it to the calling function and remove the last digit from the number passed in, just like you did in … | |
Re: You could always post the function used to delete the database so we could look at it. Why do you load the database for each choice and save it to file everytime you change the data? Unless there's a reason to do otherwise keep the data in RAM as long … | |
Re: It is certainly possible, but the specifics of how to do it depend on how the file is set up. You need to know exactly how the file is set up and exactly what you want to do with the information you extract. | |
Re: An int sounds fine. You might consider declaring a function to randomly select an int between 0-6 and passing it the array of players (as per StuXYZ) they can eliminate and have the return value be the int selected. If the element of the player array with the int selected … | |
Re: Move line 32 to between line 14 and 15. Only call srand() once per program. Call srand() before any calls to rand(). Declare the variable answer in main() and pass it to thinkUpNumber() by rerence or store the return value of thinkUpNumber() in answer. | |
Re: [code]int nums; cout << "How many numbers do you want to enter?: "; cin >> nums; cout << "Enter " << nums << "numbers:"; for(int count = 0; count < nums; ++count) { cout << "enter number # " << count + 1 << endl; cin >> num; }[/code] | |
Re: As per your first post, now find the min and the max value of the array and display the values to the screen so you can prove you have the correct value. | |
Re: First welcome to the board and using code tags on your first post! void arrays::Talk(hold&, keep&) The correct syntax would be: void arrays::Talk(string& hold, int& keep) However, since both hold and keep are member variables they are accessable by all member functions irrespective of whether hold and keep were declared … | |
Re: Welcome to the board and thanks for using code tags! In order for the value of toty in main() to retain the change done to it in drawmore(), you need to send it to drawmore() by reference instead of by value. Change the declaration of drawmore() appropriately. Not that you … | |
Re: 1) In my version I'd use a third vector to hold the results which eleminates to erase from either of the two source vectors, but you can do it as you please. Are duplicates allowed in either of the source vectors or the result vector? 2) use two iterators, one … | |
Re: [code]for(int i=2; i <= 100; i++) { bool isPrime = true; // Check to see if i is prime, print i out if it is. for(int j=2; j <= sqrt((double) i); j++) { if(i % j == 0) //what does the above line mean? //it means i isn't prime, true, … | |
Re: >>hoe can i disply a message to show the user that what he\she should to do? Maybe by displaying the required insturctions on the screen using stdout. Maybe something like this? cout << "You now have a bomb that can be used to blow up a wall." Such instructions and … | |
Re: Doesn't relate to error messages, but: [code]void setSize( int astSize); void setSpeed(int astSpeed); int setSpeed() { return astSpeed; } int setSize()[/code] when you declare functions with the same name and different arguments it is called overlaoding the function. This can be a very useful tool. However, in your case I … | |
Re: There is plenty of memory available on the C++ forum server so please try to use complete sentences to clearly explain your problem and ask a pertinent question. As it stands I don't have the foggiest idea what question you are asking or assistance you areseeking. Maybe a moderator will … | |
Re: Programs don't write themselves. You need to have some sort of a plan before you can do anything. You have successfully created an array of 24 ints, assuming the closing curly brace was intentionally left off of your snippet for the purposes of you post or unintentionally snippet by the … | |
Re: I don't routinely use the command line so this response may be in error, but I don't think so. argc gives the number of arguments passed on the command line and argv the array of strings representing the arguments. So if argc is one the only argument passed is the … | |
Re: Start by defining what a perfect number is. Is a perfect number one that equals the sum of it's factors other than itself? If so, then determine all the factors of the number, arrange them in ascending order, and add all but the largest one together. If that sum is … | |
Re: First, you will need to learn how to use code tags, see the announcement and the sticky threads at the top of the board, when posting code to this board. Without many of the more respected people who visit this board won't bother to respond to your post because the … | |
Re: Here's a brute force method that should work. Make a list of all line segments using every 2 point combination and count them. These line segments represent all possible unique lines defined by the set of points. However points, or line segments, that are colinear need to be taken into … | |
Re: [code]ostream & operator << (ostream &out, BigNumber n) { double temp = n.getCoefficient(); if (temp == 0) { out << 0; } else { out << temp << " x 10^" << n.getExponent(); } return out; }[/code] | |
Re: while ( (choice != 'H') || (choice != 'h') || (choice != 'R') || (choice != 'r') ) //not sure why this is not working try && instead of ||. If I'm reading your code correctly, the only time you want the loop to run is if all 4 conditions … | |
Re: Looks like you are missin a } on line 53 to close the do/while loop and you have one too many } at the end. | |
Re: There is no single formula. In general you will find the amount of change in X and the amount of change in Y and add it to the current values of X and Y. Sounds like you could use trigonometry and then you'd have to decide whether to use radians … |
The End.