1,359 Posted Topics
Re: I could be wrong, but I think the problem is in the [icode]insert_node()[/icode] function, specifically this clause [code] else { before_ptr->next = new_rec_ptr; new_rec_ptr = after_ptr; }[/code] I'm pretty sure you meant for this to be [code] else { before_ptr->next = new_rec_ptr; new_rec_ptr->next = after_ptr; }[/code] I've also noted a … | |
Re: I would recommend moving the file open and close operations out of the loop; even if it were working, the way you are repeatedly opening the file causes the file position to get reset each time, with the result that each number would overwrite the previous, causing only the [i]last[/i] … | |
Re: Since you are already testing for wins, we can use that to simplify the loop exit. First we'll add a Boolean variable named [icode]win[/icode] and initialize it to false: [code] bool win = false;[/code] Then we'll simplify the test for winning: [code] for (int i = 0; i < 8; … | |
Re: What is happening is that, because the header file is being included in both of the compiled files, the two globals are indeed being re-declared, once in each file. You need to change the header so that both are declared as [icode]extern[/icode]: [code]#ifndef MAIN_H #define MAIN_H 1 extern int a; … | |
Re: Are you sure that it is line 45 of the main.cpp file? AFAICT, the problem is on line 45 of playlist.cpp, where you have the print() function incorrectly associated with class 'contact'. | |
Re: First off, you need to edit your post so that the code is in [[i][/i]CODE] tags - the forum software does not retain indentation, so the code is unreadable unless you use the tags. Second, just what do you mean you need to 'change it to function type'? Do you … | |
Re: Please edit your post by putting [[i][/i]code] tags around the code sample. The forum software does not retain indentation by default, so with the code tags, it is very difficult to read the program. [b]EDIT:[/b] I should have been paying closer attention when I replied. The real advice should have … | |
Re: [url=http://support.microsoft.com/kb/99261]Microsoft Support KB article 99261[/url] gives two methods of clearing the Windows console in C++: using [ICODE]system("cls");[/ICODE] and using a function which, while complicated, should be more or less drop-in: the most difficult part of it is the need to get the console handle, which can be gotten from [url=http://msdn.microsoft.com/en-us/library/ms683231]GetStdHandle()[/url]. … | |
Re: If you don't mind me asking, why are you using C-style strings for the username, password, etc., when you've already used a [icode]string[/icode] for the [icode]user[/icode] variable? Wouldn't using a C++ style string be much easier? Also, I would recommend breaking your program up into separate functions, especially the login … | |
Re: Interesting. I was able to compile and run the program correctly under GCC, which leads me to think that the problem is with your project file rather than the code itself. I may be wrong, however... | |
Re: Not quite. What [icode]setw()[/icode] does is not indent the text; rather, it sets the [i]field width[/i] of the text, with the right side of the text by default going to the rightmost column of the field (this is called 'right justified' text; you can explicitly set it to left-justify using … | |
Re: Did you actually mean to mark this 'solved'? You seem to mark it almost as soon as it was posted. Also, as has been explained before, [icode]void main()[/icode] is incorrect, despite the fact that the compiler says it is acceptable. Please use [icode]int main()[/icode] in C++ programs, always. | |
Re: I believe this will fix an number of issues with the code: [code]#include <iostream> #include <iomanip> #include <string> #include <sstream> #include <cstdlib> using namespace std; void setColor(int color); int main() { const int SIZE = 5; double response[SIZE] = {0}; double responseTotal = 0, responseAverage = 0, responseHigh = 0, … | |
Re: When you say it "won't run", do you mean it doesn't compile? Or that it crashes? Or that it runs, but not correctly? Can you be more specific? The first thing I notice is that the [ICODE]AddressBook[/ICODE] type or class isn't defined anywhere. Is [ICODE]Person[/ICODE] supposed to be [ICODE]AddressBook[/ICODE]? | |
Re: [QUOTE=NathanOliver;1707230]Line 31 should be [icode]b = int(a);[/icode][/QUOTE] I think you meant [icode]a = (int) b;[/icode], or maybe [icode]a = static_cast<int>(b);[/icode]. Just saying. [b]EDIT:[/b] Just noticed that the variables were reversed, too. I've fixed that now. | |
Re: The first step, sadly, is to clean up your code formatting; as it is, it is inconsistent and hard to read. The next step would be to have the code check for when the user chooses to exit. This can be done simply by testing the user input. The third … | |
Re: The best way to do it is to have an integer variable, initialized to zero, which will hold the number of times the letter appears. You would then have a [url=http://www.cprogramming.com/tutorial/lesson3.html][icode]for()[/icode] loop[/url] going from 0 to 79 (that is, it would continue while the index would be less than 80), … | |
Re: Well, let's start with what you've already tried. Can you post your existing code, if any (using CODE tags, if you please)? Do you have any specific questions about how to do this? | |
Re: I see two major problems with the min/max code as it is now. First, when you attempt to call the function [ICODE]max_min_two_arrays[/ICODE], you did not give it's arguments; as a result, the function isn't actually getting called (it simpley returns the pointer to the function, which, since nothing is assigned … | |
Re: Ah, there it gets complicated, as [icode]static[/icode] has a different meaning when applied to variables and methods in a class (as opposed to local variables in a function or method). Here, it indicates that the variable or method belong to the class, as opposed to the individual objects of that … | |
Re: What specifically is happening? Does it fail to compile? Does it freeze or crash? Does the initial "Enter a number" prompt print? Regarding [ICODE]cin.get()[/ICODE], that is specifically for reading in a single character, which you don't seem to be doing anywhere here. In what way did it fail when you … | |
Re: Please put your code in code-tags in the future, to preserve formatting. Since the site does not preserve formatting by default, you should always put code samples between code tags. #include <iostream.h> #include <conio.h> int main() { int number[5]; cout<< " enter the number \n"; for (int i=0;i<=5;i++) { while … | |
Re: Probably the easiest solution is to define a structure type (or a class, if you've gotten that far in your studies), and then declare a vector of that type. Something like the following should do: [code]struct Book { long isbn; std::string title; std::string author; bool available; }; std::vector<Book>;[/code] | |
Re: When you apply [ICODE]sizeof()[/ICODE] to a pointer, it does not return the size of the object pointed to; rather, it returns the size of the pointer itself. Thus, you will need to use [ICODE]size[/ICODE] instead of [ICODE]sizeof(sortedArray)[/ICODE] in the [ICODE]Print()[/ICODE] method. I would further recommend moving [ICODE]size[/ICODE] into the class … | |
Re: Check the class definitions for Room and Monster, and make sure that there is a semi-colon after the last closing brace. | |
Re: I hate to sound like a broken record, but you really need to get your code formatting fixed. As inconsistent as it is now, it's almost impossible to read. As for the problem, the issue is that you are passing the whole array to the sorting function, rather than just … | |
Re: How are you compiling this - using g++ in the console directly, using a Makefile, or using an IDE such as XCode? Are you certain that the library itself (not just the header file) is being included in you libraries? | |
Re: I have noticed a few different things that you might want to fix about the program, aside from the problem you've mentioned: [list] [*] The code formatting is very inconsistent; I recommend you be more careful about it. [url=http://www.gidnetwork.com/b-38.html]This page[/url] is a good reference for how to style your code … | |
Re: While WaltP may seem brusque, he's actually quite knowledgable; you'd do well to listen to him on this point. As for how to format code, WaltP's earlier link (which I'll re-post [url=http://www.gidnetwork.com/b-38.html]here[/url] for you, in case you missed it) is an excellent primer on the subject [url=http://en.wikipedia.org/wiki/Indent_style#Allman_style]This link here[/url] gives … | |
Re: Assuming I'm understanding this correctly, what you need to do is combine a regular [ICODE]for()[/ICODE] loop conditional with the test for the end of the loop as you have it above: [code]for (int i = 0; (i < iterations) && (p != currentlist.end()); i++) { // code goes here }[/code] … | |
Re: There is an additional tool named [url=http://en.wikipedia.org/wiki/Apropos_%28Unix%29][icode]apropos[/icode][/url] which allows you to search through the man pages for a given word or phrase. As for networking, specifically, there are some excellent tutorials online for that, with [url=http://beej.us/guide/bgnet/]Beej's Guide to Networking[/url] being one of the best-known and most respected. For information on … | |
Re: Without seeing the code for your main() function, my guess is that you are using soemthing like [code] cin >> ch;[/code] to read in the character where the player chooses an option, correct? If so, you will want to clear the input buffer using [ICODE]cin.ignore()[/ICODE] immediately after that. What is … | |
Re: When WaltP spoke of counting line and using needing to use an integer for the array index, he was (I assume) speaking of the variable [icode]linecount[/icode], not the array itself. The array can, and probably should, be of type array of [ICODE]double[/ICODE]; but for any array, the indices should be … | |
Re: Personally, I would have done it somewhat differently, using an array of the following structure: [code]struct TeamRecord { string name; int yards; int passyards; int points; }[/code] But that's just me. Note that I used integers for the various stats; this is because all of the stats you are interested … | |
Re: Because of the way the standard buffered stream input works, there is no way to capture the control characters using the <iostream> functions. You will need to use OS-specific functions to get raw keyboard input. In the case of Windows, it will also depend on whether you are using Win32 … | |
Re: As an aside: I'd strongly recommend breaking this up into multiple header and implementation files, both to make it more modular, and to reduce the amount of clutter in the main program file. Here I've done this for you to show you how to do it, if you haven't done … | |
Re: As an aside, please use [icode]int main()[/icode] instead of [icode]void main()[/icode]. While some compilers accept [icode]void[/icode], it is not actually correct according to the C++ standard. On a related topic, under the current standards (both C++98 and C++11), the older C-style library headers all start with 'c' and do not … | |
Re: I'm guessing that the easiest solution involves recursion, and specifically that it is closely related to the integer-to-string algorithm: you accumulate the changes on the stack and rejoin them as the function calls return. | |
Re: There are two things that occur to me about [icode]insertAfter()[/icode]; first, that in the current version you aren't testing for the end of the list; second, that you want to insert the new node [i]after[/i] the node pointed to by [icode]ptr[/icode], but right now, you have it [i]replacing[/i] [icode]ptr[/icode], instead. … | |
Re: Does it work with two strings of greater than zero length? If it does, you may need to test for the string length for both strings. | |
Re: What is happening, what problems are occurring? As it is now, the program won't actually do anything, as you never call [icode]report()[/icode]. | |
Re: You do need to install the version of Code::Blocks with MinGW bundled, however. It sounds like the OP may have tried using the installer for the IDE alone. I do have to agree with Adak about [url=http://www.pellesc.de/index.php?page=start&lang=en]Pelles C[/url] - it is about as simple as compilers get. | |
Re: I believe that the problem arises from using counter1 as both the loop index and the counter for the number of times the extra number appears. Try the following code instead: [code]void printInts ( int randomArray[], int size, int& extra ) { int counter; for ( counter = 0; counter … | |
Re: What seems to be the problem with it? It looks as if it should do what you want, but we need to know what problem you are having in order to help solve it. Also, please put your code examples in CODE tags in the future. The forum software does … | |
Re: The problem with the name length comes from using [ICODE]gets()[/ICODE], which doesn't check the size of the array it reads into; in this case, if the name is more than 20 characters long, it will overflow the buffer and cause a crash. You should always use [ICODE]fgets()[/ICODE] instead, or better … | |
Re: A Graphical User Interface program, i.e., a typical Windows program, as opposed to one in a text-only console window. GUI programs are more flexible, but a lot harder to write, which is why most introductory courses stick to console applications. | |
Re: First off, please use CODE tags around your code samples in the future; the forum software does not retain the code indentation, and without the formatting the code is almost unreadable. Second, the data you posted isn't in Comma-Separated-Values (CSV) format, but in a space-separated format. This doesn't seem to … | |
Re: Curiously, when using Code::Blocks 10.5 (MinGW GCC 4.4.1), I get the following result from the same dataset: [code]John Doe T00001264 Freshman Second 0 Jane Doe T00012345 Senior First 3.62[/code] I'm not sure what the cause of the discrepancy in the results is. | |
Re: Nevermind, I see Narue found the problem, which I had missed. | |
Re: You need to have an index on the monthNames[] array, otherwise what it will return is the pointer (address) of the array rather than the value. [code]#include <iostream> #include <iomanip> #include <string> using namespace std; int main () { double avgRain = 0; double rainSum = 0; int count = … |
The End.