1,358 Posted Topics
Re: A common one is [ICODE]cin.get()[/ICODE]. It will work as long as you have a "clean" input stream. | |
Re: This is your problem right here. There are a lot of problems with it:[CODE] void setRate(float r) { rate = r; }; int getRate(void) { return setRate(); }[/CODE] [list=1] [*]Inside getRate(), you are attempting to return the value returned by setRate(), which has no return value because it's specified as … | |
Re: The [B]"arrow" operator[/B] is used with pointers to objects to access an object's members [B]via the pointer[/B]. From what I can tell though, your variable "hp" is not a pointer, it's an actual object. Try replacing the "arrow" operator with the "dot" operator: i.e. [iCODE]hp = hp.next;[/iCODE]. The [B]"dot"[/B] operator … | |
Re: None of your sample classes have semi-colons after their definitions. Is this an error in your example or does it appear in your code as well? Without those closing semi-colons, the compiler will get VERY confused.[CODE] class SampleClass { // member declarations }; //<---required semi-colon[/CODE] | |
Re: I'm not trying to be harsh, but this needs a lot of work. Line 12 is not legal C++ syntax. If you want an array of variable size, you need to use a pointer, dynamic memory management functions (operator new[] and operator delete[]), a proper destructor, and variables to track … | |
Re: @OP (on-topic): Class inheritance is based on a "base" or "general" cases/classes and "derived" or "specialized" cases/classes. The properties of the base class are designed in such a way that it applies to all objects of that class. Conversely, the derived classes are designed in such a way as to … | |
Re: What sort of behavior are you getting? What does the code that's before it do? Your solution to this situation lies in those details. Unfortunately, we don't have them so all that we can do is speculate at best. | |
Re: Go back to your chapter on functions, then answer these questions: How do you write the definition of a function? The header is the first line of the definition.[CODE] int myFunc(type myParam) { //function header /* ... function body ... */ return someReturn //return statement } //end of function[/CODE] How … | |
Re: The problem is that you're combining different types of inputs. getline() reads up to, [B]extracts and discards[/B], the newline character that exists at the end of a line of input. The extraction operator (>>) reads up to, [B]and leaves[/B], the newline character at the end of a line of input … | |
Re: You should change this to a "priming read" arrangement:[CODE] int someNum = 0; //declare and initialize input variable cout << "Please enter a non-zero value: "; //priming prompt cin >> someNum; //priming read while (someNum != 0) { //begin while loop for (int i = 0; i < 20; ++i) … | |
Re: Can you be more specific about the information in the error? I think the problem is with your definition of the EMove enum. The members of an enum are all integer constants, not chars. This means that keUp is not literally the char 'w', it's the integer 119, 's' is … | |
Re: I have a feeling your conversion process is what [URL="http://www.daniweb.com/forums/thread329755.html"]your other thread[/URL] is about. Take the result of the equation I suggested in [URL="http://www.daniweb.com/forums/post1407872.html#post1407872"]this post[/URL] and combine it with an output manipulator to produce a continuous string of padded "numeric" characters. Then, when reading the file, use a character-based input … | |
Re: [URL="http://en.wikipedia.org/wiki/Farkle"]Make a Farkle game[/URL]. I did a console-based version of it, these are the classes I used: [list][*]Die [*]DieSet [*]FarkleGame [*]GameConfig [*]Player [*]PlayerSet[/list] I also had a bit field called "ruleFlags", but don't worry about that unless you really want to. While working on it, I found out that they … | |
Re: If you detect the "case" (upper/lower), then use mathematics, you should be able to save a ton of code. I think you may want to consider something like this:[CODE] if (islower(input)) { //detect a "lower" case character value = 10 + (input - 'a'); //perform the translation } else if … | |
Re: Well, I'm having some trouble reading your code because you didn't use code tags. What I can tell you though is that this: `if ((X == 'V') || (X == 'I') || (X == 'R') || (X == 'U') || (X == 'S'))` is not correct. This will cause your … | |
Re: Do you know how to traverse a single-dimensional array?[CODE] const int SIZE = 6; //declare a constant for the array size int myArray[SIZE] = {0}; //declare and initialize the array for (int i = 0; i < SIZE; ++i) { //traverse an array/row myArray[i] = i; }[/CODE] You can use … | |
Re: Hmmm... Perhaps answer this question: Which part(s) of this code are you responsible for? Are you expected to make your code fit with the provided code? Which section(s) of the code are provided? | |
Re: I think you may want to describe the program's use case a little better and provide the relevant code. I don't know OpenGL, I don't do anything with graphics just yet, but it sounds like it's probably a dirty input stream. Console applications tend to behave similarly to that if … | |
Re: [url]http://www.cplusplus.com/[/url] There are all sorts of references and a decent tutorial there. Oh, and don't expect to learn it all in one day... | |
Re: You have arguments to your 3 functions but you haven't declared or initialized them before using them. Additionally, your function prototypes don't match your functions' definitions. I think I see what you are trying to do, but you haven't implemented it correctly. This is what you need to do to … | |
Re: Fill this in:[CODE] class Queue { //what goes here? };[/CODE] Then, instantiate it in your main() and manipulate it accordingly. | |
Re: [QUOTE][CODE]void Enemy::Attack([B]Player a[/B], Enemy b){[/CODE][/QUOTE] Yes, it's a scoping issue. You're passing a [B]copy[/B] of a Player. You should be passing either a [B]pointer[/B] or a [B]reference[/B] to the Player. | |
Re: [B]>>Please only respond if you actually want to help. Not to name names, but some people on here are just rude.[/B] Speaking of rude... Good luck with your assignment. | |
Re: You have a large amount of numeric input in this program. When you use the "extraction operator" ( >> ) for numeric input, it leaves a lingering "newline" character on/in the input stream, making the stream "dirty". To remove this lingering character, place a [iCODE]cin.ignore()[/iCODE] immediately after each numeric input … | |
Re: I don't think they're just jumbling it. I think that, for whatever reason, they're trying to re-order the data diagonally from top-right to bottom-left rather than horizontally. You are correct though. [URL="http://www.daniweb.com/forums/announcement8-2.html"]We need to see some effort first.[/URL] | |
Re: [QUOTE=Transcendent;1404773]it did work man. can you write it.[/QUOTE] [URL="http://www,daniweb.com/forums/announcement8-2.html"]Are you joking?[/URL] It's 2 extremely simple changes. Change num to i inside the loop then add another output line. It's not that hard. | |
Re: Doesn't really surprise me, an error like that usually implies a missing function implementation. Glad you figured out what was missing. | |
Re: I don't see any tests to verify that the files have been opened successfully. Do you know that the output file is actually being opened properly? Example:[CODE] #include <iostream> #include <fstream> using std::cout; using std::ofstream; int main() { ofstream outFile("filename.txt", std::ios::out | std::ios::trunc); //declare the output file stream if (outFile.is_open()) … | |
Re: Well, it's a little tough to help much due to a lack of context. I think it would be helpful if you posted a little bit more code so that we can see your overall context better. Generally though, if you need a section of code to repeat you'd use … | |
Re: The new[] operator doesn't work like other operators. To use it, you must have a pointer that you are storing the return value to.[CODE] dataType *pDataType = 0; //declare a NULL pointer to a dataType pDataType = new dataType[arraySize]; //create an array on the heap, store it's address in the … | |
![]() | Re: getch() is part of the conio.h header, which you haven't included. That's actually a good thing, it really should never be used, it is not a standardized header. Instead, put a cin.get() directly before your return 0; (Line 46). |
Re: The first question you need to answer is "How do I add a fraction?". Once you answer that, you know what you need to do in plusEquals. Take that same basic question and apply it to the other methods. [B]>>The problem require to ask the user for the fractions[/B] Yes … | |
I'm really intrigued by OOP, I feel that I can help most people with OOP questions reasonably well, but I still have a lot to learn and there's something that bothers me. What is the best way to write the program's main() if I want to create a truly OOP … | |
Re: Why are you dropping into assembly? Why not just use the C++ arithmetic operators and loop statements? | |
Re: Care to elaborate on the errors? We're not mind-readers. Looks like you need to pay closer attention to your variable names. I can see several instances of variable names not matching. On Line 9, you declare a double called "dfistnumber". It seems you want to input to it on Line … | |
Re: [QUOTE][CODE]bool isSame=false; do { bool isSame=false; for (int i=1; i<=corners; i++) //... }while (isSame==true);[/CODE][/QUOTE] This section of code is a big no-no. The "isSame" on Line 1 is not the same "isSame" as the one on Line 4. Your do-while loop defines a program scope that is separate from the … | |
Re: Dev C++ is crap. Don't use it unless you have to. Use Code::Blocks or VC++ Express instead. I wouldn't use a "Windows Application". I would suggest a "Console Application". Then, you create a *.cpp file and put your code in the *.cpp file. EDIT: Oops, AD beat me to it. | |
Re: std::bad_alloc is what is known as an "exception". To use exceptions, you need to use a try ... catch block. If an error is encountered, you "throw" (not return) an exception. The exception is then caught by the appropriate catch block. Some functions, such as new, automatically throw them for … | |
Re: [QUOTE][CODE]double getPrice() const; //<----- naughty semi-colon use {return price;}[/CODE][/QUOTE] Lose the semi-colon after the const. You do not place a semi-colon after the header line of a function's definition. That turns it into a function prototype and then you're left with a dangling statement block that's not recognized as the … | |
Re: [QUOTE=Mr_PoP;1402083]dude it's just for jokin with my real friends i dont use my knowledge to piss the people off , besides i just wanna know why it does not work on XP :)[/QUOTE] Regardless, this can be construed to fall under the "Keep it Legal" section of the [URL="http://www.daniweb.com/forums/faq.php?faq=daniweb_policies"]Member Rules[/URL], … | |
Re: Find the min/max as you normally would, then store the indexes of the low/high values, in addition to the values themselves. You would then modify your output stream based on the current index rather than the actual value. If your current index for your output matches either stored index, you … | |
Re: For starters, you need to move your struct definition out of your main(). Put it after your using statement. Your recordCount should be separate from your struct, it should not be part it. After you verify that you have successfully opened your file, you should do an initial read to … | |
Re: You have 2 problems: First, you have the same problem as in [URL="http://www.daniweb.com/forums/thread326696.html"]your previous thread[/URL]. Unless you're some sort of prodigy, you can't just barf something into your code and expect it to work correctly. You need to start taking the time to think about how you write your output … | |
Re: [QUOTE=Ninjah;1401823]I don`t uderstand how it is possible because I`ve tried to open a file as follows: ifstream infile("C:\Users\NINJAH\Documents\Visual Studio 2008\Projects\myfile.txt"); but it does not work. The thing is that I`ve tried to put double \ characters and it worked..no errors it reads from the file. And when I use the … | |
Re: [QUOTE=alainigban;1401842]I'm sorry for posting the whole code here, i think the problem is not really on line 121. gerard4143 i've tried your suggestion, b[/QUOTE] It's not, it's on line 58, like Gerard said. It's flagging 121 because your error around Line 58 closes the if's scope prematurely thus preventing it … | |
Re: Wasn't this same issue already discussed in [URL="http://www.daniweb.com/forums/thread325697.html"]your introductory thread[/URL]? Not only are you double-reading, which will mess you up really bad, you are using a for loop. It is better to use a while loop instead of a for loop to read your file, it's much easier, and less … | |
Re: I suggest you hand-trace your program's execution. I see a couple things: [LIST=1][*]Your class does not have a constructor. it's relying on the compiler-provided default which does not appear to be sufficient for this class. [*]Because you don't have any constructors, your Student member values are not being initialized properly. … | |
Re: What exactly do you mean by "it generates only one column"? Can you provide a sample output? [URL="http://www.daniweb.com/forums/announcement8-3.html"]Also, some example source code would be beneficial.[/URL] | |
Re: [B]>>#1). Write a loop that will print the values in a 20 element vector named quantity to the screen. (When I compile the code it increments by 10 for the 20 values and I'm pretty sure this isn't correct)[/B] It's not actually incrementing by 10, it just looks like it … | |
Re: Let's just say you're lucky it worked. Technically, what you have written is [B]accurate syntax[/B], but it is [B]logically incorrect and very dangerous[/B] code. Because it's simply a pointer to a single char, there is not sufficient memory allocated where that char is stored to hold an array of char. … |
The End.