- Strength to Increase Rep
- +8
- Strength to Decrease Rep
- -2
- Upvotes Received
- 59
- Posts with Upvotes
- 49
- Upvoting Members
- 48
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 2
I am the lord of the wind.
Re: Are you familiar with functions? If not, it's a good time to start learning about them. As pointed out by others above, breaking the task into smaller steps helps a lot. So, let's focus on building a line first. Take a look at these lines: 122222221 123333321 123444321 There is … | |
Re: > Less overhead Not really. I don't know what compiler you're using, but any decent one would seize the opportunity to perform [tail call optimization](http://en.wikipedia.org/wiki/Tail_call) in np complete's code, and generate output **identical** to the one corresponding to an iterative implementation. > easier to read I think this is the … | |
Re: You can always use the C version of ostringstream -> [url]http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/[/url] | |
Re: Careful! The relevant threads in the Software Development and Web Development forum categories are not sticky! Or at least that's what I see... ![not_sticky](/attachments/large/2/not_sticky.PNG "not_sticky") | |
Re: >I fixed it. i downloaded the dll from a website and added it to my bin folder. Downloading dlls from random sites is not a very wise thing to do. You never know what kind of code these dlls may contain. I'm talking about security issues. Your pc could as … | |
Re: > Ok so what i was thinking was add the nodes in sequence. so the text file would be Does it have 4 legs? Does it purr? Cat Dog Does it swim? fish What you do here is called printing the tree using [preorder traversal](http://en.wikipedia.org/wiki/Tree_traversal#Depth-first_traversal). > Does this **require** recursive … | |
Re: > There are no tests what-so-ever in your code. Yes, there are. They are inside the [strncpy](http://www.cplusplus.com/reference/clibrary/cstring/strncpy/) and [strncat](http://www.cplusplus.com/reference/clibrary/cstring/strncat/) functions. > I've had some people say to do result_maxlength-1 They are right. In your first `concat` call, this -> `result[result_maxlength] = '\0';` turns to -> `c[5] = '\0';`. You're going … | |
Re: I have a couple of questions: What happens if you increase the number of calculations you have to make per iteration? Are you sure you're timing the hardcoded approach properly? What optimization flags are you using? Check this out: #include <windows.h> #include <iostream> #include <algorithm> #include <vector> using namespace std; … | |
Re: > I was thinking about somehow using a static member that all the matrix cells will be defined by their value + the static value. This is a very interesting idea. It also is easily generalized. You could have a stack of (different) operations and apply them in order when … | |
Re: cin is fine too. What you need to do is clear your stringstream's buffer and state before you use it again. Either add this here -> `ss.str(""); ss.clear();` before using ss or create ss right before you use it. Also, the condition in your if statement should be `!ss || … | |
Re: Now, let's add some [basic AI](http://ideone.com/2ND3o). Nothing too serious, just a simple, suboptimal (you could use the [KMP algorithm](http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm) to improve it), history matcher. It searches the user's previous moves for recurring patterns and uses this information to predict the user's next move. For anyone interested in more advanced stuff, … | |
Re: > `num = ((-b) + sqrt(b*b-4*a*c))` > `den = (2*a)` It's unlikely that `sqrt(b*b-4*a*c)` will be an integer (or even a rational number). A better approach would be something like this: ... p = -b q = b*b-4*a*c r = 2*a ... print "x = (" print p print " … | |
Re: [Looks](http://ideone.com/9pjS4) like [Perl](http://www.perl.org/) to me. | |
Re: Or better yet, vectors, since the number of lines in the file is not known during compilation. #include <iostream> #include <fstream> #include <vector> #include <string> using namespace std; int main() { ifstream fin("main.cpp"); vector<string> lines; string curLine; while (getline(fin, curLine)) lines.push_back(curLine); for (size_t i = 0, size = lines.size(); i … | |
Re: >I wonder which is better :to start learning a new programming language or develop my skills in the C++ language ? Both have advantages. What you should do depends on several things. One of these things is what is it that makes you face this dilemma. Do you have some … | |
Re: There is a problem with the logic you use to generate the random indexes. Let's start with something simpler. Suppose you want to get three unique random values from a unidimensional array of four elements. The easiest way to do this is by using [random_shuffle](http://www.cplusplus.com/reference/algorithm/random_shuffle/): #include <iostream> #include <string> #include … | |
Re: >im thinking of a game in the Command Prompt Read [this](http://www.cplusplus.com/forum/articles/28558/) first. IMO, the thing with the best result-to-effort ratio you can do right now is grabbing a graphics library (e.g. [SFML](http://www.sfml-dev.org/)) and writing a simple [scrolling shooter](http://en.wikipedia.org/wiki/Shoot_'em_up#Types). And if you 're worrying about your artistic skills, don't. Computer software … | |
Re: ATB - Ecstacy -> [url]http://www.youtube.com/watch?v=1bVYgYW6410[/url] | |
Re: Here's an idea: #include <iostream> #include <string> template <class A, class B> struct SameType { static const bool Result = false; }; template <class A> struct SameType <A, A> { static const bool Result = true; }; template <bool C, class True, class False> struct IfThenElse; template <class True, class … | |
Re: > I've tried to do some research on this minimax thing, but I couldn't find anything helpful. How much did you search? I just googled **connect four c++ minimax** and I found this [video](http://www.youtube.com/watch?v=kHJRdHCSQLE) on youtube. In the description of that video, I found this [link](http://users.softlab.ece.ntua.gr/~ttsiod/score4.html), There, you can see … | |
Re: Judging by the way you use getline, `teamnamesquestion` must be a char array. The problem with this is that `teamnamesquestion == "no"` performs a pointer equality check, that will, obviously, always return false. If you don't believe me, try this: #include <iostream> using namespace std; int main() { char str[10]; … | |
Re: > You are missing endl or flush at the end of most of your output statements. This is a joke, right? It has to be a joke, because neither is it true nor does it have anything to do with the OP's problem. The OP's problem arises from mixing istream::operator … | |
Re: So, what you essentially want is **efficient calculation of [multinomial coefficients](http://en.wikipedia.org/wiki/Multinomial_theorem#Multinomial_coefficients)**. I googled that, and the first link I got was [this](http://home.comcast.net/~tamivox/dave/multinomial/index.html). | |
Re: > not all control paths return a value This means that you have code that looks like this: ReturnType load_image(ArgType1 arg1, ArgType2 arg2, ...) { //... if (some_condition) return something; // What happens if some_condition is false? // You don't return anything in that case... } > The first two … | |
Re: @OP: [Moschops](http://cplusplus.com/forum/beginner/72307/#msg385772) is right. I fixed these errors, compiled the code you posted and got the [expected output](http://zifda.wordpress.com/2011/12/16/morphing-pada-opengl/#more-331). | |
Re: > If you are writing a simple program that resembles a language interpreter, and it is capable of computing non-trivial equations of more than a fixed size, then you really are talking about writing an intepreter. You'll want to go the whole route of tokenizing and parsing the input, even … | |
Re: If you have to do it using sscanf, you could do it like this: #include <iostream> #include <cstdio> using namespace std; int main() { string path = "main/articles/animals/giraffe"; char * cPath1 = new char[path.size()]; char * cPath2 = new char[path.size()]; sscanf(path.c_str(), "%[^'/']/%[]", cPath1, cPath2); string path1(cPath1), path2(cPath2); delete[] cPath1; delete[] … | |
Re: I think you may be using the wrong language for this. It's certainly doable, but there are much better alternatives (at least on windows). One such alternative is [Autoit](http://www.autoitscript.com/site/autoit/). Here's an example that does what you want with notepad: $file = FileOpen("C:/in.txt") $line2 = FileReadLine($file, 2) Run("notepad.exe") WinWait("[CLASS:Notepad]") ControlSend("[CLASS:Notepad]", "", … | |
Re: You don't really need to understand how std::map works in order to understand how to use it. I have an idea. Let's ask the OP which version (s)he finds easier to implement / understand. This one -> http://ideone.com/ojv1H ? Or this one -> http://ideone.com/Vz9oh ? | |
| Re: > Why not just create array as a large array? Say int array[1000]? While this would work if this is just homework, it's not a good idea in general, as it creates a huge security hole in the application. [Here](http://stackoverflow.com/questions/2039953/frame-pointer-program-counter-array-overflow)'s an interesting thread I found regarding that matter. > The … |