- Strength to Increase Rep
- +11
- Strength to Decrease Rep
- -2
- Upvotes Received
- 152
- Posts with Upvotes
- 134
- Upvoting Members
- 84
- Downvotes Received
- 4
- Posts with Downvotes
- 4
- Downvoting Members
- 2
Mathematical software developer
- PC Specs
- Windows 7 Visual Studio 2013
Re: I think that you should probably think about indenting your code a little, so that the various blocks are a bit easier to pick out. Also, I think that it's generally best to have [icode]main()[/icode] return [icode]int[/icode] rather than [icode]void[/icode], that way you can check the return value of the … | |
Re: You have mixed up the way your variables are used in your functions. For instance you call [icode]toOctal[/icode] on line 19 without any arguments, but [icode]toOctal[/icode] take a [icode]long int[/icode] argument and the way they are used in the function will give you an infinite loop! The function [icode]toHex[/icode] also … | |
Re: Hmm, what you have shown here are three *functions* or *methods* from a class. Two of the methods are used in the setup of your output (`setOutputStream` and `setMessageCallback`) and the other (`outputMessage`) is used to actually output the things that you want to output. You haven't given much code … | |
Re: [QUOTE=Tomi1988;1532016]I don't know. What is the solution?[/QUOTE] The solution is to write your own arbitrary precision integer version, which isn't as complicated as it sounds. | |
Re: > i thought of the boolean route but i dont know how to implement it. I cant even get the Part 1 to work Think about what are the biggest and smallest numbers that have six digits, all valid pass codes must be between these two values, right :) | |
Re: I reckon that you'll get rid of some of your compilation errors by correcting lines like this: if (head == NULL >> tail == NULL) I think that you just want something like: if ( ! head && ! tail ) | |
Re: OK, you're current program is not going to do what you want it to at all. If I were you, I'd start by looking at the question more carefully and breaking it down into a number of small parts. So, the question is: [quote]write a c++ program that given the … | |
Re: Use std algorithms where possible: #include <string> #include <algorithm> // Store the password in a string std::string password; /* Do things to get password from user */ // Count the upper and lower case letters size_t upper_case_count = std::count_if( password.cbegin(), password.cend(), std::isupper ); size_t lower_case_count = std::count_if( password.cbegin(), password.cend(), std::islower … | |
Re: There is a school of thought that says that you should not really design your class such that you're having to actually do things that could fail in the constructor. You should instead "inject" the things that the class needs directly into the constructor, which should simply be a thing … | |
Re: > `for(int i=0;i<10;std::cout<<i++<<std::endl); Yikes! Don't write code like this :) In general, tricks in code made code unreadable in the long-term. I think it's a reasonably good rule that one should *never* write a loop unless if can't be avoided. I have a hierachy of things that one should try … | |
Re: You can do it with a single array and a single value of the type in the array (an `int` in your case). Use the single value as a temporary to swap the first and last elements and then the second and penultimate elements and so on. Or, you could … | |
Re: I agree with the comments so far that you probably need to explain what it is that you're trying to acheive when writing this code. All these raw pointers are generally not necessary in modern C++. Further to what Decepticon said about your assignment operator, your programm `main` looks like … | |
Re: You want it to "work better" how, exactly? Are you looking for general code standards tips, hints on using more C++-like paradigms? etc... | |
Re: You can check for even numbers using the `%` operator on an `int`: int even = 2, odd = 5; std::cout << "even: " << even % 2 << " odd: " << odd % 2 << std::endl; any even number will return 0 when you do `% 2` to … | |
Re: I notice that you're making a vector of vectors of doubles. Are you planning to use this like a matrix to do algebra on and such? Or, are there other constriants (all the "rows" have to be the same length, or something)? If these things are true, then you might … | |
Re: Even broken up into individual little programs, I don't think these will even compile. Probably best to get them compiling first and go from there. Efficiency is not your biggest issue right now. If you don't know how to do that, then ask questions about the errors that occur when … | |
Re: You can open any file and access the bytes in it. However, making sense of those bytes is much more difficult in the case of something like an mp3 or jpg file. You'll probably want to use an external library for that... | |
Re: I think that you need another `for` loop inside the `count` function, which will go over the array of random numbers and count each value. You should also use more descriptive names for the arguments to the `count` function; so `x` and `n` should be something more like `values` and … | |
Re: I think that you could do something like point 2 using Zero Install, or something similar. Although, I'm not sure that I want things auto uninstalling! Zero Install might allow a more dynamic installation of programs (as well as a more traditional model). In regard to point five, I think … | |
Re: Hmm, I'm not sure what your original question is asking exactly. I do have some comments on your snippet though. 1. If you use `QList` to hold stuff, then the `QList` is actually holding pointers to the stuff for you. So, if own the objects in the list, then you … | |
Re: Just a comment, but if you have an array of strings, you can iterate through them with one of the std algorithms to count the ones that you want. So, to count the number of "hello" strings, you can simply do: auto number_of_hellos = std::count( S.cbegin(), S.cend(), "hello" ); It's … | |
Re: What compiler are you using? It might be helpful if you posted the error message that you're getting (or at least the first couple of errors that you get) :) | |
Re: You can't do this: tmm += ("Minutes: " + tmm); th += ("Hours: " + th); `tmm` is an `int`. What would it mean to increment and `int` with the sum of a character array and an `int`?. There are probably a bunch of other things wrong with this code … | |
Re: What code do you have as your attempt at this problem at the moment? | |
Re: have you tried adding some debugging output to your code? For example, print out the value of the indices and values that you're trying to swap in that inner if statement... | |
Re: You've definitely created logic of sorts for doing the tasks in the question, but the logic isn't *encapsulated* in any functions. The question definitely says that you should write *functions* to add data to the class room's attributes, etc. Also, you should avoid the use of `goto` in your code---you … | |
Re: I would say: - Don't use the macro version - Use the const int version if you plan to use the variables in arithmetic (your intentions are clear to the reader this way), I.e. if the numerical value of the thing is actually important to you. - Use the enum … | |
Re: I was basically really hungry for most of my early twenties. My housemates noted this and started calling me Ravenous. It seemed like a cool user name so I use it wherever I can. It's actually kind of common, so I also use Ravenacious (which I don't think is a … | |
Re: Does something like this do what you want? std::uint32_t Checksum = 0; std::uint32_t CheckSum2 = 0; std::uint8_t* Ptr = Pixels; int K = Width < 12 ? 1 : 12; for (int I = 0; I < K; ++I) //Start at 0 offset { for (int J = 0; J … | |
Re: who can help me when i shut down my window ,it show a massage which tell us .(waiting for background programme to close ).any advice would be appreciated .Thx all friend It's probably best to start a new thread if your question is totally unrelated to this thread, which your … |