1,359 Posted Topics

Member Avatar for crystalll

Crystalll: As an aside, in the future, please put CODE tags around your code samples. The forum software does not retain formatting by default, so your code loses it's indentation unless it is in code tags.

Member Avatar for Schol-R-LEA
0
609
Member Avatar for Desh2350

You may want to look at the answers given [url=http://www.daniweb.com/software-development/cpp/threads/395461]here[/url], as many (if not most) of the same issues were addressed there, for the exact same problem set.

Member Avatar for Schol-R-LEA
0
4K
Member Avatar for learner guy

As it is, all that you are checking is whether the region between the source and the destination is clear; you never check to see if the destination is actually on that diagonal. [code]bool validBishop(char board[][8],int inputs[]) { int sr=inputs[0] , sc=inputs[1] , dr=inputs[2] , dc=inputs[3]; int i, j; bool …

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

What you want is a [url=http://en.wikipedia.org/wiki/Sorting_algorithm][i]sorting[/i] algorithm[/url], from the way you describe it. You can find descriptions of [url=http://en.wikipedia.org/wiki/Category:Sorting_algorithms]various sorting methods on Wikipedia[/url]; I personally suggest the [url=http://en.wikipedia.org/wiki/Gnome_sort]Gnome Sort[/url], as it is very simple and easy to debug, though not particularly efficient.

Member Avatar for ppt123
0
237
Member Avatar for Vasthor

For line 12, you declare [ICODE]counter[/ICODE] as a reference to [ICODE]int[/ICODE]. References are similar to pointers in that they do not hold a value in themselves, but instead refer to another variable. Thus, [ICODE]counter[/ICODE] won't work unless you assign a reference to it. I suspect that for [ICODE]counter[/ICODE] (and [ICODE]overall[/ICODE]) …

Member Avatar for Schol-R-LEA
0
249
Member Avatar for t2ac32

To start with, you need to be more careful about capitalization. C++ is a case-sensitive language; [icode]MyList[/icode] is not the same as [icode]MyLIST[/icode] or [icode]myList[/icode]. This alone could be the source of some of the errors. Secondly, you don't want to [i]rename[/i] an object to something else; you want to …

Member Avatar for t2ac32
0
1K
Member Avatar for luftey

One thing strikes me most of all, that you did not, in fact, close and re-open the file as the instructions said would be necessary. This is probably the main reason it isn't working, and the data you are getting is probably garbage that was already in the allocated memory.

Member Avatar for Schol-R-LEA
0
235
Member Avatar for iGuardian

I strongly recommend that you first simplify the program thusly: [code]/* File: Rainfall.cpp Description: Write a program that reads in the average monthly rainfall for a city for each month of the year and then reads in the actual monthly rainfall for each of the previous 12 months. The program …

Member Avatar for iGuardian
0
1K
Member Avatar for harde

One thing I noticed (aside from your indentation, which needs improving) is that the project said to set the file to [url=http://www.cplusplus.com/doc/tutorial/files/]append mode[/url]. Thus, you should change the open() call to: [code] file.open("output.txt", ios::out | ios:app);[/code] This ensures that the data is added to the end of the file, rather …

Member Avatar for Schol-R-LEA
0
235
Member Avatar for Thermalnuke

You need to move the final word count out of the while() loop. You also need to check for in.fail() in the loop itself, in case there's a problem with the input that did not appear when it was opened. [b]EDIT:[/b] I think I know where the problem lies: you …

Member Avatar for Thermalnuke
0
167
Member Avatar for Dakot

Your description of the problem you're having wasn't very clear; you say you want to search from an input file, but right now, all you're doing is reading in data from the console. Can you explain the problem better? If you don't mind me asking, why do you have the …

Member Avatar for Schol-R-LEA
0
135
Member Avatar for Thermalnuke

I am assuming you meant Visual C++, not Visual Basic. Otherwise, you've gotten very confused about the language you are using :?: The error indicates that the function [ICODE]_tmain()[/ICODE] is missing. Now, in UNICODE enabled Windows programs, [ICODE]_tmain()[/ICODE] is the equivalent of the [ICODE]main()[/ICODE] function in regular C++. That you …

Member Avatar for Thermalnuke
0
112
Member Avatar for abhiagro

To begin with, please use [[i][/i]code] tags around all code samples in the future, especially ones as large as this. This is very important, as the code tags force the software to retain the indentation; without them, the code is almost impossible to read. [code] #include <iostream> #include <fstream> #include …

Member Avatar for Schol-R-LEA
0
270
Member Avatar for jeevsmyd

You never allocate the memory for the [ICODE]name[/ICODE] and[ICODE] branch[/ICODE] variables, so when you copy the strings to them, they end up writing to random locations in memory. Add the following to the [ICODE]new[/ICODE] and [ICODE]delete[/ICODE] operators and it should fix the issue: [code]void *student::operator new(size_t size) { void *p; …

Member Avatar for jeevsmyd
0
409
Member Avatar for cafegeo

I have noticed that there are some problems with the indented code posted by Captain Jake, specifically that some braces appear to be missing. I've used AStyle to automatically re-indent the code, which I hope will help make the main bug clearer: [code] { int quantityamount1[3]; for(int i=0; i<3; i++) …

Member Avatar for PrimePackster
0
159
Member Avatar for Tokenfreak

You would do better with a stack of strings rather than chars, I think. You then could tokenize the input into strings, and push the strings onto the stack. A better approach might be to use a discriminant union (that is, a structure with a type marker and a union …

Member Avatar for mikrosfoititis
0
2K
Member Avatar for lmytilin
Member Avatar for mikrosfoititis
0
193
Member Avatar for eblanco1

I agree with Pseudorandom21 on both of these points, especially the latter: when I tested the code myself (using GCC 4.4.1 running through Code::Blocks 10.5 for Windows), I found that the program would hang and crash until I changed that particular loop to test for end-of-file. As for the box …

Member Avatar for eblanco1
0
245
Member Avatar for jcAmats

Oops, I missed that. You need to check whether [ICODE]line_counter[/ICODE] is zero in your loop conditional, otherwise it will try to read an non-existent line, causing the segfault. [code]while(choice != 'q' && line_counter > 0)[/code]

Member Avatar for jcAmats
0
11K
Member Avatar for Octet

If you put the final [ICODE]while()[/ICODE] conditional at the beginning of the [ICODE]main()[/ICODE] function, and put braces around the rest of the function, it should loop around the whole function: [code]#include <iostream> #include <fstream> #include <windows.h> #include <string> using namespace std; #define DEBUG 0 int Password = -1; int Option …

Member Avatar for Octet
0
303
Member Avatar for learner guy

Aside from some extremely inconsistent formatting, I can see a number of issues with this: [list] [*] You don't appear to be testing whether the destination (destiny?) is still in the same column as the original position. I realize that you aren't addressing horizontal movement yet, but you should at …

Member Avatar for Schol-R-LEA
0
2K
Member Avatar for Awais Ali

I am not familiar with a pseudo-stack, myself. Stacks are common enough, yes, but not pseudo-stacks, at least not in the usual terminology. Can you tell us the context in which you've encountered this term?

Member Avatar for Awais Ali
0
217
Member Avatar for desolatebeast

Actually, I think that thines01 misunderstood the project requirements; what you describe is what is called a 'shell' in the Unix/Linux world. You won't necessarily be getting command-line arguments for this program, but will be reading in a command line and executing it, then reading another command line and executing …

Member Avatar for thines01
0
164
Member Avatar for nyfan68

The specific problem you mention comes from a missing closing brace in the [icode]RationalNumber()[/icode] c'tor. However, it is not by any means the only problem in the code. For example, the assignment operator should be something like this: [code]RationalNumber& RationalNumber::operator= (const RationalNumber &right) { numerator = right.numerator; denominator = right.denominator; …

Member Avatar for Schol-R-LEA
0
386
Member Avatar for jlharri9

You need to actually instantiate a [ICODE]TestScores[/ICODE] object using the non-default c'tor, which is the only place you actually throw the exception in question.

Member Avatar for Schol-R-LEA
0
219
Member Avatar for fmasroor

[QUOTE=fmasroor;1702614]2. Why use pointers when the array can be declared as global?[/QUOTE] I assume you're talking about passing arrays to functions, in which case the answer is, because global variables in general are a Bad Thing, or at least enough of a bad thing that you will want to use …

Member Avatar for Schol-R-LEA
0
119
Member Avatar for fmasroor

About half of these are warnings rather than errors (mostly ones relating to standard functions Microsoft considers 'deprecated', which in this case means, "Don't use the standard version, use this spiffy safer new version that happens to lock you into our compiler"). The main reason they appear at all is …

Member Avatar for Schol-R-LEA
0
334
Member Avatar for Ccuteri60

The problem is that, unless you define them yourself, there are no comparison operators for the [ICODE]Date[/ICODE] type. The compiler does not know how to compare one [ICODE]Date[/ICODE] value with another.

Member Avatar for Ccuteri60
0
375
Member Avatar for crc0002

The error messages are fairly straightforward: most of the member functions you are calling do not actually exist. You need to define and implement a constructor for [icode]Node[/icode] which accepts a string as an argument, plus all of the member functions which you are using ([icode]SetNorth()[/icode], etc).

Member Avatar for Schol-R-LEA
0
9K
Member Avatar for jackmaverick1

To address the last (non-)question first, you could use the predicates from [url=http://www.cplusplus.com/reference/clibrary/cctype/][ICODE]<cctype>[/ICODE][/url] to check the characters if you really needed to. You'd probably have to check against a few different things to get exactly the character set you were looking for. On a side note, with a modern C++ …

Member Avatar for Schol-R-LEA
0
351
Member Avatar for carolinatech

How are the boxes defined in the program? Or is that part of what you need help with?

Member Avatar for WaltP
0
77
Member Avatar for Sgt. Pepper

As a side issue, why didn't you define the border functions using a [icode]for()[/icode] loop? It would be a lot easier to read and change, if you needed to: [code] const int LINE_LENGTH = 75; // ... void borderDown() { const char o = 209; for (int i = 0; …

Member Avatar for Schol-R-LEA
0
282
Member Avatar for jonspeidel

Certainly, you can write functions that work recursively, yes. Here is your function written in just such a fashion: [code]#include <iostream> #include <cctype> using namespace std; void repeat(); int main() { repeat(); } void repeat() { char s3='n'; cout << "Would you like to perform another operation? (Y/N)" << endl; …

Member Avatar for WaltP
0
253
Member Avatar for MachDelta

The linker isn't losing track of things; the problem lies in the header, and more specifically, the function prototypes for those two functions. The prototypes are declared as: [code]void clearBoard(int, char); void printBoard (char, int);[/code] Whereas the functions themselves are actually: [code]void clearBoard(int, char*[]); void printBoard (char*[], int);[/code] This is …

Member Avatar for Schol-R-LEA
0
130
Member Avatar for mzimmers

I believe that at least one part of the problem can be fixed by changing the function prototype such that [ICODE]nbrCells[/ICODE] is a [ICODE]const long[/ICODE] reference rather than just a [ICODE]long[/ICODE]: [code]template <class T> int getVectort(ifstream & s, const long & nbrCells, typename vector<T>::iterator iter)[/code] This will allow for either …

Member Avatar for mzimmers
0
622
Member Avatar for pudge343

Actually, there is one more means of repetition, called recursion, but most C++ programmers consider recursive functions to be both too confusing and too inefficient to be used regularly. Being a Lisp programmer, I find this attitude silly, but there it is. :P Recursion consists of writing a function that …

Member Avatar for Schol-R-LEA
0
253
Member Avatar for mftbob

This may be a bit advanced of a suggestion, depending on just how the professor is teaching the course, but: one way to improve the readability of the code would be to use an enumeration for the three different states rather than using numbers for them. Combining this with the …

Member Avatar for Schol-R-LEA
0
4K
Member Avatar for physicist

Surprisingly, it is actually valid C, or rather, it [i]was[/i] valid about twenty-five years ago. The function argument declarations are of a form that was used in 1st edition K&R C, but which most modern compilers wouldn't accept as far as I am aware (though interestingly, GCC accepts it without …

Member Avatar for Schol-R-LEA
0
416
Member Avatar for kjcjk

While I am not certain why it appears to be bypassing the input, I can tell you why it is going into an infinite loop: at no point do you change or test [icode]tries[/icode], which means that if the input is not a valid number in the right range, it …

Member Avatar for WaltP
0
236
Member Avatar for lmytilin

While it is not the only problem with the code, the main issue is that you are using an output file for input. You will want to change the program thusly: [code]#include <iostream> #include <fstream> #include <string> const int LinesToPrint = 10; using namespace std; int main() { ifstream inputfile; …

Member Avatar for WaltP
0
593
Member Avatar for kingcong83

Getting back to the original question, the code below fixes most of the syntactic errors in the code, though I did not attempt to correct the logical flaws without a clearer idea of the intended behavior: [CODE]#include <iostream> #include <iomanip> #include <string> #include <cctype> using namespace std; const int ARRAY_SIZE …

Member Avatar for Schol-R-LEA
0
157
Member Avatar for lo0lo0999

I gather your intention is to have a ring buffer queue, correct? I think that this solves most of the problems you are having: [code]#include <iostream> const int SIZE = 6; class queue { private: int a[SIZE + 1]; int front; int rear; public: queue(); ~queue(); bool insert(int i); int …

Member Avatar for lo0lo0999
0
306
Member Avatar for bwilson1

The first thing I recommend is that, in order to simplify reasoning about the Simpson's Rule function, you should move the part that gathers the elevation data from the function proper, storing the data in an array which you can then pass to the function. You'll need to allocate the …

Member Avatar for Schol-R-LEA
0
183
Member Avatar for IT FRESH

There are a number of issues with this code that I can see, with the foremost being with the way you are getting the time. As it is, you are reading in the time as an 8-character array, using [icode]gets()[/icode] (which is deprecated as being unsafe, but that that's a …

Member Avatar for Schol-R-LEA
0
132
Member Avatar for greimykudau

From the thread title, I assume you are a Java or C# programmer. The [ICODE]main()[/ICODE] in C++ works very differently from the equivalent in Java, being a bare function not associated with a class. You would write a [ICODE]main()[/ICODE] function something like this: [code]int main() { // code goes here …

Member Avatar for greimykudau
0
162
Member Avatar for NickPatton

I'm not sure about [icode]e[/icode], but for [icode]d[/icode], you will want to use the [url=http://www.cprogramming.com/tutorial/modulus.html]modulo operator[/url], [icode]%[/icode]. For [icode]e[/icode], as I said I'm not sure, but I think it has to do with integer division by 5.

Member Avatar for NickPatton
0
242
Member Avatar for vlaskiz

You can use the combination of [url=http://www.cplusplus.com/reference/iostream/manipulators/setw/][icode]setw()[/icode][/url] and [url=http://www.cplusplus.com/reference/iostream/manipulators/setfill/][icode]setfill('0')[/icode][/url]. [code] cout << setw(2) << setfill('0') << day;[/code]

Member Avatar for vlaskiz
0
155
Member Avatar for mikrosfoititis

The issue is not with the header files, [I]per se[/I], but with the object files that the compiler produces before linking. You need to have the compiled object files linked together in the final version of the program, which (depending on how you are doing things) means having them together …

Member Avatar for mikrosfoititis
0
291
Member Avatar for smata

What do you need help with? What have you been able to do so far? Do you know the syntax for declaring classes, for inheritance, for invoking a method, etc?

Member Avatar for tkud
0
189
Member Avatar for pendo826

In the definition of the [icode]Weapon[/icode] structure, the first letter of the [icode]Name[/icode] member is capitalized. In the code referring to it, the first letter is lowercase ([icode]name[/icode] instead of [icode]Name[/icode]). It's the sort of mistake anyone could make, and would have been easy to find except that the compiler …

Member Avatar for pendo826
0
130

The End.