1,359 Posted Topics
![]() | Re: As is explained [url=http://www.cplusplus.com/reference/clibrary/cstdlib/rand/]here[/url], the maximum value for [ICODE]rand()[/ICODE] (defined as [icode]RAND_MAX[/icode]) is implementation defined, but is at least 32767 for a compliant compiler and library. As for how to get the specific range you want, you need to use a combination of modulo ([icode]%[/icode]) and addition or subtraction. So, … ![]() |
Re: There are several libraries available for Linux, some of which I can assure are already installed and others are easily installed from Synaptic. Examples I can think of off the top of my head include [url=http://www.gtk.org/]GTK+[/url], [url=http://www.wxwidgets.org/]WxWidgets[/url], and [url=http://qt.nokia.com/products/]Qt[/url]. | |
Re: You'll need to give us some idea of what you've tried yourself already. No one in this forum is going to do your homework for you. | |
| |
Re: A few notes: [list] [*] Yes, you would need the [ICODE]<cctype>[/ICODE] header for [ICODE]tolower()[/ICODE]. I could add that you'd want to also have the [ICODE]<cstdlib>[/ICODE] header for the calls to [ICODE]system()[/ICODE]. [*] Are the [ICODE]system()[/ICODE] calls actually needed? If I am not mistaken, Visual Studio 2010 automatically pauses console programs … | |
Re: I agree with Rohan121212; you need to give more specifics about the program. The answer to the question would depend on just how the end of the loop is indicated. If you are given a number of cases to enter before the loop begins, then it is fairly straightforward: [code] … | |
Re: To begin with, please use [[i][/i]code] tags around your code samples. This will cause the forum software to retain the formatting for the code, making it far easier to read. Second, using [icode]void main()[/icode] is incorrect in C++. While the older standards allowed it, it was always non-portable and discouraged, … | |
Re: Nikesh2014: As Narue says, you didn't actually post a question, which makes it hard to give a useful answer. What seems to be the problem? (Aside from the fact that you are using an ancient compiler, that is. Turbo C++, I'm guessing, given how many schools seem to have standardized … | |
Re: First off, permit me to recommend a different representation of the cards, one which would almost certainly be easier to work with: [code]enum SUITS {HEARTS, CLUBS, DIAMONDS, SPADES}; struct Card { int face; SUITS suit; }; Card deck[52]; [/code] Of course, your coursework may not have covered structures and enumerations … | |
Re: Let's start by separating the algorithm from the (extraneous) output: [code] #include <iostream> int gcd(int a, int b); int main() { int a, b; std::cout<<"Enter the A Integer: "; std::cin>>a; std::cout<<"Enter the B Integer: "; std::cin>>b; std::cout << "The Greatest Common Divisor of " << a << " and " … | |
Re: Might I suggest using a reference to a [icode]vector<Pizza>[/icode] rather than a pointer to an array? It would solve most of the issues revolving around pointers and allocation, I think. I realize that it may not be an option with a school project, but if it is acceptable, it would … | |
Re: Actually, it predates computer programming entirely; it comes from conventions in mathematical notation, where i, j and k are traditionally used to indicate the indices of arrays and the iterative variables of [url=http://en.wikipedia.org/wiki/Summation]summation[/url] (big-sigma) operations. | |
Re: Well, what specifically are you having trouble with? | |
Re: [QUOTE=mc3330418;1697694] Also, is there a way to write a function and then have it output what is going on in that function? [/QUOTE] Now, I have to ask: just what do you mean by 'have it output'? Where do you want to results sent - to the console, to the … | |
Re: I should point out that Dev-C++ is itself a bit old, as it hasn't been maintained after 2005. Also, neither the [url=http://www.codeblocks.org]Code::Blocks[/url] IDE or the [url=http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express]Visual C++ Express[/url] IDE suffer from this particular problem - both pause the output automatically at the end of a console program. | |
Re: You are having the [url=http://www.daniweb.com/software-development/cpp/threads/395461]same problem[/url] that your classmate lbgladson had: you're declaring and defining the functions as [icode]void[/icode], most of them should in fact return a [icode]Rational[/icode] value. | |
Re: First off, you should use [[i][/i]code] tags around your code samples in the future. I expect one of the mods will do this for you, but you should not rely on this, if only because it makes extra work for them. Second, there are a number of issues with the … | |
Re: The code as written isn't valid; unlike in some languages, you cannot have a code block that isn't part of a function in C++. Mind you, it is generally inadvisable to have code (as opposed to declarations) in a header file, but that's not the cause of the problem, per … | |
Re: The process is pretty much what you would expect: first you find the Greatest Common Divisor of the two integral parts, and then divide each by that. The result will be the reduced form of the rational number. The easiest way to find the GCD of a number is the … | |
Re: You're not the first to make this mistake about [icode]fflush()[/icode]; it sounds reasonable, but the problem is that it doesn't do what you are expecting. In C, the [icode]fflush()[/icode] function only operates on output, forcing it to finish immediately rather than remain in the buffer. Applying it to an input … | |
Re: Hard-coding is the practice of placing literal constants (e.g., the number 1.0) directly into the program code, rather than holding them in named constants. Repeated use of hard-coded values, or use of inobvious values, is generally frowned upon, as it can make maintenance harder (because if have to change it … | |
Re: You can find extensive information, including sample boot loaders, at [url=http://www.osdev.org]OSDev.org[/url]. I would recommend being careful about posting to the fora there, however, as they expect you to carry your own weight, and a blanket request such as this one is likely to get negative reactions. That having been said, … | |
Re: I am certain that someone here can, if you show us what you've already done first. Doing the work for you, however, would not be considered 'helping' by most of the folk here. (I've actually been criticized for posting too much 'help' at times, rather than giving the original poster … | |
Re: How do you use it for what, and where? the BYTE marker is meant to tell the assembler that you're working with a 1-byte value; you use it to remove ambiguity in places where the value could be either a byte or a word. I don't really see anything like … | |
Re: While Gribouillis's answer is correct, it could probably use more explanation, because the dot-member notation is used somewhat differently in C++ than in Python and it may be somewhat confusing. In C++, variables have an explicit type, unlike in Python, where variables are typeless (type being a property of the … | |
Re: This may seem simple, but the question carries with it more than you might suppose. First off, what do you mean by 'a: drive'? This may seem like an obvious point, but it isn't: the meaning of the drive lettering and so on is a feature of the OS itself, … | |
Re: You're getting closer with this, but in this case, you do not want the double-quotes around the variable names; double quotes are used to demarcate the beginning and end of a string literal. Thus, you should try the following: [code] cout <<"Encrypted digit:" << digit_three << digit_four << digit_one << … | |
Re: To quote one famous comment made many years ago, undefined behavior could mean that the compiler causes demons to fly out of your nose, if the compiler writer so chooses and is able to implement it. Undefined means just that: that the compiler can give whatever results the compiler writer … | |
Re: Well, the first thing you need to know is that [ICODE]getline()[/ICODE] is not a standard C function (as of the C99 standard, at least to the best of my knowledge). It is an extension added in the GNU version of the stream I/O library, and while it is widely supported, … | |
Re: Actually, the problem is that you are not enclosing the [ICODE]switch()[/ICODE] block in braces, and as a result, only the first case is being seen as in the scope of the [ICODE]switch()[/ICODE] statement. This is no different than if you had written an if statement like this: [code]if (something) statement1; … | |
Re: [QUOTE=sundip;1642648]add return type for BasicLCG(); and BasicLCG(unsigned long); It should solve you first 4 compilation error[/QUOTE] Yes, but it does nothing for the redeclaration error immediately below it. C doesn't allow function overloading; you'll need to give the two different functions different names. Furthermore, those two functions are constructors in … | |
Re: To get some of the theory behind this, see [url=http://forums.devshed.com/showpost.php?p=2001351&postcount=14]here[/url]. That discusses the role of linkers and inclusion headers, and how they are used in C and it's relatives. This may help put what Narue said into perspective. While what I wrote then focuses on reusable code libraries, the principles … | |
Re: Let's break this down somewhat; the increment operator isn't specific to [ICODE]for()[/ICODE] loops, and for that matter, [ICODE]for()[/ICODE] loops don't necessarily use an increment. Let's take the simplest case of a separate increment expression: [code]i++;[/code] Now, whether this compiles to a single assembly language operation or not depends on the … | |
Re: You don't have any return value for the case where [ICODE]counter[/ICODE] does not equal 5, so the caller basically gets whatever junk happens to be in the returned value register - and since any value other than zero (false) evaluates to true, the return value is almost always going to … | |
Re: The main issue I see with this is that you don't have [ICODE]break[/ICODE] statements at the end of the cases. This means that the first case will 'fall through' to the second, which results in the [ICODE]fee[/ICODE] always being set to 20. | |
Re: Actually, AD, in this case it is possible to use Visual Studio as an IDE for NASM; [url=http://justcheckingonall.wordpress.com/2008/03/05/using-nasm-in-visual-studio-6-and-2003net/]this page[/url] explains how to integrate NASM with VS6. It's a bit dated, so some of the details about NASM itself may be off (e.g., paths), but it shouldn't take much tweaking to … | |
Re: I think that the issue the line [code] imul %ecx /* eax = eax*ecx */[/code] Here you should be multiplying by %ebx rather than %ecx, as %ecx still holds a pointer to the end of the string, whereas %ebx should be holding the decimal place which you want to multiply … | |
Re: What aspect of it do you need help with? | |
Re: Would you mind posting the class declaration (in the header file), as well? It would clarify a number of things about the code. From what I am gathering, though, the Bullet class has a number of instance variables, something like [code]int x, y, startX, startY, dx, dy; char* ptr;[/code] There … | |
Re: What is actually going wrong? I can see a number of issues, but I would like to know what you specifically are trying to fix. | |
Re: It has to do with the additional declarations inside the [icode]if[/icode] statements, and the rules for scoping of variables. By re-declaring the variable [icode]newFee[/icode] inside of the [icode]if[/icode] statements (as a different type, at that), you are masking the original declaration of [icode]newFee[/icode] at the beginning of the function. Therefore, … | |
Re: [b]EDIT:[/b] Apparently, you posted your corrected version just minutes before I posted this answer. You seem to have the basic idea now, yes. You're on the right track from where you'd been, but you still haven't quite grasped the function syntax. Specifically, you need to remove the semi-colon at the … | |
Re: I'm not certain I'm following you, here; you should be able to nest any sort of loop inside of any other loop, and there's no need for an [ICODE]if()[/ICODE] statement. Can you explain just what you're trying to accomplish? I can hazard a few guesses as to what you might … | |
Re: To begin with, you seem to be having trouble understanding the structure of functions such as [ICODE]main()[/ICODE]. In the function implementation, you do not put a semi-colon at the end of the function header - you only do that with function prototypes, which you probably haven't covered yet. Also, you … | |
Re: I agree with Narue's advice, if it is possible - if you don't have a backup of the earlier version, and aren't using version control, it will be much harder to undo the changes. However, I was wondering if your course of study has covered classes yet; given the number … | |
Re: What I gather out of all this is that you want to be able to write a loader for an executable file, correct? If so, then the reference text you want is [i][url=http://www.iecc.com/linker/]Linkers and Loaders[/url][/i] by John Levine. It covers several executable file formats in detail, including the DOS and … | |
Re: Don't you need to link GRUB (or whatever multi-boot loader you're using) into your image as well? | |
Re: You really can't write a boot-loader in C++, at least not entirely; the first stage, at the very least, would have to be in assembly language, and given that most C++ compilers produce only 32-bit code, you'd probably have to set the system into 32-bit protected mode before you could … | |
Re: The comment here is incorrect, which may shed light on how the loop is failing as well: [code]while (in_stream >> number) //in_stream >> number returns a Boolean value of true if the operation has been successful.[/code] The [ICODE]>>[/ICODE] operators, as a rule, return a reference to an [ICODE]istream[/ICODE] not a … | |
Re: While I know you're new with this site, it should be mentioned that [url=http://forums.devshed.com/c-programming-42/crc24q-implementation-846352.html]Cross-posting[/url] is frowned upon as it can cause a duplication of effort on the part of the two communities. It's generally considered best not to cross-post at all, but if you feel you would get better results … |
The End.