1,288 Posted Topics
Re: #include <string> ... ... string user_input; cin >> user_input; and since you are compelled to use a c-string for your function, char* c_string = user_input.c_str(); | |
Re: Pointers can be explained pretty fully in just a couple of sides of paper. A whole book on them would be enormous overkill. They are very simple. The problems with them tend to come when people try to explain them with bad metaphors involving streets and house numbers, or envelopes … | |
Re: http://www.cplusplus.com/doc/tutorial/files/ | |
Re: What command are you using to compile this? | |
Re: > I am unable to link or locate the folder #include. \#include isn't a folder. It's an instruction to the pre-processor to find the file you specify right after \#include and copy it in. There is no folder named "\#include" > If I can't resolve this problem can I use … | |
Re: We call the function f(5). What does f(5) return? It returns 2 \* f(4). What does f(4) return? It returns 2 \* f(3), so let's put that back into "what does f(5) return?" What does f(5) return? It returns 2 \* f(4) = 2 \* 2 \* f(3) So what … | |
Re: > why we can't check if array is not initialized. How can you tell the difference between a byte that has been "initialised" and a byte that has not been "initialised", just by looking at the byte? It's meaningless. | |
Re: What are you struggling with? How far have you got? Do you understand how to actually do this? By which I mean, can you tell me which of these two words is a palindrome: CATFISH CIVIC | |
Re: Builds (and runs) fine on my system (using gcc V4.7.3 on Ubuntu 12.04). | |
Re: What are you trying to do? Tell us what you want the macro to transform this `events2( b) a;` into. | |
Re: http://stackoverflow.com/questions/982659/quickly-create-large-file-on-a-windows-system | |
Re: Do you know how to do this on paper? If you simply write down the steps of how to do this on paper, the code version will be obvious. | |
| |
Re: The base class' constructor and destructor are private, so an inherited class can't call them. Which is bad. | |
Re: How do you know what the values of i and j are to give us the example? Please sghow us the actual code that produced that actual output. | |
Re: > whereas my sorting for X seems be to sorting correctly. I don't think it is. Your program suggests that -999 is greater than -9, which isn't true; -999 is nine hundred and ninety less than -9. Flip round the `<` and the `>` on all your sort functions. | |
Re: > The EnterExpense() function only creates one line instead of many (if the user wants to continue entering more info). Because you reopen the output file every time you go round the loop. Open it once before the loop, close it once afterwards. | |
Re: Spot the difference time: `«` vs `<<` `»` vs `>>` The one on the left is not C++ code. The one on the right is. This is what happens when you copy and paste code. | |
Re: `sum/6` is an int divided by an int. An int divided by an int will give you back an int, always. What's 3/2? 1. What's 29/6? 4. To get a double answer, you need one of the two values to be a double. An easy way to do this is … | |
Re: Each set locks a mutex, then changes the variable, then unlocks the mutex. Make sure the struct's internal variables are private so only the set function can change them. | |
Re: To add to what has been said, I see this most commonly when writing code for embedded hardware, in which some physical real world sensor or signaller is permanently linked to a specific memory address. For example, if you look in the manual for your embedded hardware and see that … | |
Re: You need your loop to contain two different sets of behaviour. One for when i is 1-3 and 7-9, and one for when it is 4-6. | |
Re: > For this sets of code below, how do I write such that 4 sets of x,y coordinates will be stored in ShapeTwoD? This doesn't store them with pointers. It just stores an array of four points. Does it have to use pointers? struct point{ int x; int y; }; … | |
Re: Because your compiler thinks using ctime is *such* a bad, *bad* idea that it's not going to let you do it unless you specifially tell it to let you. | |
Re: You cannot store different types in a vector. However, if all your class objects are of the same base class, they are all objects of that base class, so you can store in the vector a pointer-to-base-class; each pointer in the vector pointing to an instance of your objects. vector<ShapeTwoD*> … | |
Re: A std::vector or std::array spring to mind. vector<Body> theVector; // make a new Body object here theVector.push_back(newBodyObject); Use push_back to keep adding them. | |
Re: You have hard-coded the size of your arrays: `int c[5][5],d[24],p[24][6],list[5],r;` If you need arrays that can have their size set at runtime, don't use arrays. Use C++ std::vector (or the shiny new std::array if your compiler supports it) to get arrays that you can set the size of at runtime. | |
Re: Take your value. Check it will fit in the range (so in the example above, if your value is less than 1 or grater than 3, stop now). So now you need to know how far along the range your value is. The maximum value along the range in the … | |
Re: If I understand what you're saying, your problem is that when you generate random numbers, sometimes you generate a number you have already used? So keep a record of all the numbers already used, and when you generate one, only use it if you haven't already used that number. | |
Re: Gargh! Darn double-post edit whackey hackery! | |
Re: Here's a start. I suggest you add the headers and using declarations that are needed, get it running, and then move on to the next step - outputting a list of them. int main() { string titleArray[10]; string authorArray[10]; double priceArray[10]; for (int i=0; i<10; ++i) { cout << "Title … | |
Re: The function advanceDate does not touch the appointment object you are passing into it. You are making a copy named newApp2 (like this - `appointment newApp2(e);`), altering the copy, outputting something from the copy, and then returning the copy (which is promptly thrown away). If you want to change the … | |
Re: The simple, forward-Euler method works as follows: 1) Get current value of the variable you care about. 2) Get rate-of-change of the variable. 3) Next value is current_value + (rate_of_change \* time_step) Repeat until you've gone forwards enough in time. So in this case, it looks like the time_step is … | |
Re: Your function says it returns a bool. It doesn't. It should. | |
Re: That all looks fine. Good luck with your homework. | |
Re: We can help you. How far have you got? Do you know how to get input from the user? | |
Re: Firstly, you have eight menuItems to read, and eight menuPrices, so you should be making an array of size 8 rather than 7. Otherwise, nothing here that should stop your code working. If I had to guess, your file `menu.txt` is not in the same directory that the executable is … | |
Re: The logic of your code is wrong. It is not an infinite loop but you are going to print out a lot more than you meant to. What happens at the moment when, for example, i = 40 and j = 30? | |
| |
Re: That code doesn't compile, and even if it did it probably wouldn't throw an exception. If you were very lucky, you'd get a segFault, but probably not. If your code throws an exception, and you think you can deal with it and carry on, catch it. What exception are you … | |
Re: Do you know how to make an empty C++ program that does nothing? | |
Re: It would be worth your time, at this point, to take a step back and decide what you want to do. You have currently chosen to attempt writing GUIs using the Win32 API. Let's go back a step. On a modern OS, you cannot directly change the value of a … | |
Re: What Deceptikon is saying is, for example, what happens if the user has to type '10'? You'll read the first input and think the user meant '1' Anyway, that aside, you don't need an int. Just compare against the *char*. For example, if the user enters the char '1', `if(no … | |
Re: I see your loop has a return in it. This means that the loop ends the very first time. Put the return *after* the loop. You're also using the variable that tells you how many years to run for (the user input) as the variable telling you how many years … | |
Re: `//char *cmdStr = command.c_str;` c_str() is a function. It is called like this: `char *cmdStr = command.c_str();` Second issue: The bit at the end looks like a a definition of a class function. Presumably you're not trying to define a class function; you're trying to *use* a function. In C++, … | |
The End.