1,426 Posted Topics
Re: If you want to retain what was held in the vector then before you exit your program you must write that information to a file. Then you also have to change your code so that when the program loads it loads the file into memory. Files are the only way … | |
Re: What do you need help with? What code do you have so far? If "help me please" is slang for "give me code" then you will find no one is going to "help" you. | |
Re: `char const*` should be `const char*`. May I ask why do you want to hold a constant string? | |
Re: Have you ever used [getline()](http://www.cplusplus.com/reference/istream/istream/getline/)? you would have to use a `char*` but it should work nicely. | |
Re: You dont want to use magic numbers. You want to use the constants that are supplied. | |
Re: Well what is the best score? Is it closest without going over? Is it just the closest guess? Are you trying to see how many attemps it takes to find the random number? Once you know exactly what you want then you can start writing code. | |
Re: > Don't give tips because my mind burnt out on studying functions, just give the code directly as I only need a very simple program. Thank you. You will find that most people here wont go for that. I will also take it from the code you posted that you … | |
Re: Change `for_each(newLines.begin(), newLines.end(), [](std::string& s){ reverse(s.begin(), s.end()); });` to `for_each(newLines.begin(), newLines.end(), [](std::string& s){ reverse(s.begin(), s.begin() + 10); });` to only do the first 10 characters. I assume newLines is of type `std::vector<std::string>`. | |
Re: So what is the problem you are having? No one is going to do this for you. | |
Re: A reference is a constant pointer in the sense that the reference cant be changed to point to something else. You can still change the value that reference points to. On the other hand if you pass a const reference then you cant change the value that the reference holds. | |
Re: Did you write this code? Besides the fact that there is no formating and it is mostly not standard compliant what is the issue? | |
Re: you could use a simple for loop in your main function and do a brute force method like your functions do or you could use the Sieve of Eratosthenes method which works very well. [url]http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes[/url] also on line 13 in your code you are using or which is incorrect in … | |
Re: for a set of random letters like only vowels you can create an array that holds the vowels and then use rand % (size of array) to get the index for the element in the vowel array. | |
Re: you need to put lines 35 and 36 inside the do while loop. Also dont use `void main()`. In the c++ standard it says that main returns an int. | |
Re: Where should the cursor move to? Can you show us how the input should be formated? | |
Re: We do not do your homework for you. What have you done so far? If you are having a problem with something that is one thing. To ask for us to do it for you is completly different. | |
Re: This is a classic case of stream corruption. You asked for a number and got a letter so after that all stream operations will fail. one way to stop this is to use a loop when asking for inputs. here is an example: int num; do { cout << "Enter … | |
Re: Well the intrest rate and term should be members of the class so you can use them in mutiple functions. | |
Re: You need to do the work. We will not do it for you. What code have you written so far? | |
Re: So why do you want characters? | |
Re: Well the problem you are having is you are not doing what the assignment asks. When you add to the letter if you exceed the bounds of the character set you need to wrap around to the beginning. You also don't want to modify anything that isn't a character. All … | |
Re: So what do you need? Can you assume what a college student is and what you need to have for members and functions? | |
Re: Well if the map is set up like this: map<"user-id", map<"movie-id", "rating"> Then if you want to see how many movies a person has rated you could do this: std::map<int, map<int, int> > m; // add stuff to m int numberOfMoviesRated = m["some-user-id"].size(); In the above example the call to … | |
Re: Did you check to see if prices had anything in it? What happenes if you put this after line 17 and before line 18? if(prices.size() < 2) cout << "Vector size less than 2!" << endl else cout << "Vector has 2 or more elements!" << endl | |
![]() | Re: @ rubberman >I need to know how to remove spaces from a string using pointers in C++ |
Re: I would think they are just looking for big O notation since they give no size for n. | |
Re: So what exactly are you haveing a problem with? What have you tried? | |
Re: You could write your display like this for (int i = 0; destination[i][0] != '\0'; i++) cout << destination[i] << " "; | |
Re: Your call to srand should be outside your loop. I would suggest putting it on line 15. As for you call to rand() it should look like this: `r_number = rand() % 12 + 1;`. Your if condition on line 55 is also incorrect. Can a number be less than … | |
Re: You start with a = 3. So line 2 will print a which is 3 then a gets incremented to 4. then it prints the space. Then a gets incremented to 5 then a which is 5 gets printed agian. This has to do with how the post and pre … | |
I was reading some articles on cplusplus.com and for kicks I read the template tutorial. At the very end of the section there is this paragraph: Since no code is generated until a template is instantiated when required, compilers are prepared to allow the inclusion more than once of the … | |
Re: What is the code you are using to display the diagonals? You basiclly need to invert the display logic to have it display the non diagonals. As an FYI this is how I would display the diagonals // this assumes the array is sqaure and size is the size of … | |
Re: this code will solve only this problem and will do it in 36 iterations. just did it for giggles to see if i could. if you want a generic code then you will have to do other things ;) [code=c++] #include <iostream> #include <stdlib.h> using namespace std; int main() { … | |
Re: @ nitin1 std is a namespace that all of the standard c++ functions and classes are in. A namespace is just another level of orginizing your code. You can equate it to the file cabinet metaphor. The function is a piece of paper. The file the function is in is … | |
Re: The way I would do this is to read in all of the questions into an array. After that then shuffle the array around. Here is a little example std::string questions[15]; // load the questions into questions[] srand(time(NULL)); // this seeds rand int randIndex; for (int i = 0; i … | |
Re: Don't forget that you will need to add the counter increment to the copy constructor and the assignment operator. You probobly want to have that as a seperate counter since those objects will be implicitly created. | |
Re: Is it just me or did the whole UI change in the last hour or so? | |
Re: Well one way to fix that is to see what is bigger and if the number that is being subtracted is larger than the number it is being subtracted from switch them around. Then do your normal subtraction and add a "-" to the result. `10 - 100 = -90` … | |
Re: First off your coveredarray should be of type char not int. Secondly what I would do is load guessarray with the numbers 1-9 in order. Then I would go through the array and swap the element of the current index with one that is randomly generated. To do that take … | |
Re: Well in the warning you got it says the file name can't be "aux" and you are using that. Try chnaging the name of your file to something else. | |
Re: Do you know the STL? If not check [this](http://www.cplusplus.com/reference/) out. | |
Re: I know microsoft uses -1 as true if you are using access so it makes sense that they are doing that with there compiler. AFIK any value other than 0 is considered true and I havent seen a case where that doesnt work. | |
Re: The code in your first piece of code should not compile. More than likely there is some sort of compiler extension taking care of it for you. What compiler are you using? Static arrays can only be initialized with a const size argument. | |
Re: Just as an FYI. If you call erase on a vector and you are using iterators any iterator that is after the begining will be invalidated. | |
Re: a const function can be called by a non const function. a const function can only call other const functions. the same thing applies to objects as well. | |
![]() | Re: I would suggest using something other than graphics.h. it is not supported by any modern compilers and it will only work in a dos enviroment. ![]() |
The End.