1,359 Posted Topics

Member Avatar for FARIEYRA

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 …

Member Avatar for FARIEYRA
0
132
Member Avatar for Hlopster

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] …

Member Avatar for Hlopster
0
163
Member Avatar for jankeifer

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; …

Member Avatar for jankeifer
0
348
Member Avatar for Chuckleluck

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; …

Member Avatar for Chuckleluck
0
434
Member Avatar for Firzin

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'.

Member Avatar for Schol-R-LEA
0
161
Member Avatar for mikeblitz

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 …

Member Avatar for Schol-R-LEA
0
246
Member Avatar for blackrainbowhun

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 …

Member Avatar for Schol-R-LEA
0
173
Member Avatar for Akusa

[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]. …

Member Avatar for Schol-R-LEA
0
429
Member Avatar for TheWickedKid

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 …

Member Avatar for Ancient Dragon
1
16K
Member Avatar for zaneulhaq

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...

Member Avatar for Schol-R-LEA
0
267
Member Avatar for coolbeanbob

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 …

Member Avatar for Schol-R-LEA
0
226
Member Avatar for rajatchak

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.

Member Avatar for rajatchak
0
216
Member Avatar for Taino

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, …

Member Avatar for Taino
0
123
Member Avatar for Nawaf15

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]?

Member Avatar for Schol-R-LEA
0
354
Member Avatar for PrimePackster

[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.

Member Avatar for PrimePackster
0
250
Member Avatar for harde

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 …

Member Avatar for harde
0
348
Member Avatar for ConfusedLearner

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), …

Member Avatar for bboy_fresh
0
274
Member Avatar for siabenie

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?

Member Avatar for siabenie
0
136
Member Avatar for topdos

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 …

Member Avatar for topdos
0
451
Member Avatar for Srinivas0

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 …

Member Avatar for mrnutty
0
258
Member Avatar for northrox

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 …

Member Avatar for Schol-R-LEA
0
98
Member Avatar for northrox

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 …

Member Avatar for Schol-R-LEA
0
124
Member Avatar for Brian_L

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]

Member Avatar for Brian_L
0
99
Member Avatar for Valociraptor

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 …

Member Avatar for Schol-R-LEA
0
224
Member Avatar for Kuroshi

Check the class definitions for Room and Monster, and make sure that there is a semi-colon after the last closing brace.

Member Avatar for Kuroshi
0
328
Member Avatar for EXpoZuR

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 …

Member Avatar for EXpoZuR
0
103
Member Avatar for dancks

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?

Member Avatar for dancks
0
301
Member Avatar for Madbabe

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 …

Member Avatar for Schol-R-LEA
0
77
Member Avatar for EXpoZuR

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 …

Member Avatar for EXpoZuR
0
219
Member Avatar for Ahmed2

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] …

Member Avatar for Schol-R-LEA
0
2K
Member Avatar for marcux

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 …

Member Avatar for Schol-R-LEA
0
121
Member Avatar for jcAmats

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 …

Member Avatar for jcAmats
0
385
Member Avatar for EXpoZuR

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 …

Member Avatar for EXpoZuR
0
220
Member Avatar for Jdan2388

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 …

Member Avatar for Jdan2388
0
261
Member Avatar for MediumSoda

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 …

Member Avatar for MediumSoda
0
441
Member Avatar for Sgt. Pepper

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 …

Member Avatar for Sgt. Pepper
0
299
Member Avatar for dumbc++guy

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 …

Member Avatar for Schol-R-LEA
0
213
Member Avatar for easterbunny

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.

Member Avatar for easterbunny
0
2K
Member Avatar for Kyle Willett

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. …

Member Avatar for Kyle Willett
0
182
Member Avatar for corby

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.

Member Avatar for corby
0
183
Member Avatar for mc3330418

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].

Member Avatar for mc3330418
0
84
Member Avatar for rithish

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.

Member Avatar for Schol-R-LEA
0
409
Member Avatar for nubcoder

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 …

Member Avatar for nubcoder
-1
129
Member Avatar for gameguy91

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 …

Member Avatar for gameguy91
0
262
Member Avatar for vonbv25

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 …

Member Avatar for Schol-R-LEA
0
154
Member Avatar for c fan

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.

Member Avatar for Ancient Dragon
0
240
Member Avatar for Ahmed2

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 …

Member Avatar for Ahmed2
0
321
Member Avatar for Arkinder

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.

Member Avatar for Arkinder
0
396
Member Avatar for UltimateKnight
Member Avatar for UltimateKnight
0
101
Member Avatar for Thermalnuke

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 = …

Member Avatar for Thermalnuke
0
144

The End.