Looks like you have some extra braces scattered throughout. Also, to pass by reference you have to do:
void readThreeNumbers(float &number1,float &number2,float &number3);
Dave
Looks like you have some extra braces scattered throughout. Also, to pass by reference you have to do:
void readThreeNumbers(float &number1,float &number2,float &number3);
Dave
Also, there is no reason to use global variables here. Define number1,2,3 in main and then pass them by reference to the functions.
Dave
Please post 'character.h'. I suspect something like this:
void Character::Character();
when it should be simply:
Character::Character();
Dave
Please use code tags when you post code. Also
1) you didn't define a data type anywhere.
2) the pc function that you declared is not defined anywhere.
3) the parameters to pc() need to have a type declared.
4) monitor = int something
is not valid syntax
Why don't you send us your answer and we'll check it?
Dave
1) Please wrap your code in code tags
2) Use std::string instead of char (you'll have to #include <string>) and everything should turn out much better for you :)
Dave
I think the whole thing should be wrapped in a class called Tree or something. Then Root is simply a member variable and can be accessed no problem from all of its member functions (which should be all of the function you have written).
Let us know if you have any problems converting it - this is quite a useful thing to learn and will definitely make the code much much much more reusable.
Good luck,
Dave
This is called "ascii art". You should use a 2D array if the number of rows and columns is fixed. "Pointers" aren't a solution to a problem, but rather one of many tools c++ offers. If you have specific questions let us know.
Dave
Strange - I just cleared the "browsing data" and it works again. Some googling looks like other people have had problems with chrome and css, so I'll keep an eye on it.
Thanks for the (quick!) reply!
Dave
I'm not convinced it isn't just something wrong with my installation, but has anyone else had this problem?
Here is a screenshot of daniweb.com in Google Chrome on Fedora 13:
http://rpi.edu/~doriad/Daniweb/chrome.png
And here it is (normal) in firefox:
http://rpi.edu/~doriad/Daniweb/firefox.png
Are there any known issues like this? Or can someone else tell me if it works for them in chrome in linux?
Thanks,
Dave
I'd use a std::vector<std::string>
no matter how you plan to do the recursion.
jwenting -
I agree with all of your points here. So how do you suggest we fix it? I noticed you had private messages disabled, but if you'd like to take the discussion "offline" I'd like to continue it. You can find contact info in my profile (since I think it will get "snipped" if I post it here).
Dave
This probably belongs in the 'C' forum as it is not C++.
Dave
Did you try a simpler program (still using SDL)? Try to get a < 20 line program where the timer doesn't work.
Dave
In recursion you need a "base case". Here I guess the base case is the first line of the song. So your function should probably be called PrintAllPreviousVerses(int verse) and just call it recursively decrementing 'verse' by 1. This actually doesn't seem like an ideal case to teach recursion, but maybe I just don't know what I'm talking about :)
Please mark the thread as solved. It would also be nice to write a brief description of what you ended up doing to solve it so that the next reader can share your new knowledge.
Dave
No no, you can't increment x like that, it will just turn 28 into 29!
No no, it is definitely ok to reset that variable. The problem is that you have popped the whole stack, then you are trying to get the top() of the stack, which is not defined.
This code runs fine
#include <iostream>
#include <stack>
using namespace std;
int main()
{
stack<int> number;
int x=0;
number.push(43);
number.push(34);
number.push(45);
number.push(28);
x=number.top();
while(number.size() > 1)
{
number.pop();
x=number.top();
cout<<x << std::endl;
}
return 0;
}
I'll leave it up to you to figure out the logic to get all 4 items, since this only gets 3 :)
Good luck,
Dave
Please try to get the problem to occur not in 350 lines, but instead something manageable like 20 lines.
Dave
You are not resetting x to number.top after the stack is modified. So what is happening is you are setting x to 28, then in the loop you are modifying the stack but simply outputting 28 over and over! You need to add a x=number.top()
between the number.pop() and the cout<<x.
Dave
jwenting - You are exactly right about employers needing to start from scratch. However, this doesn't seem like any inherent problem, it is just a bad (read "old") educational system!
I write (read "whine") about this every once in a while -
SNIP
Dave
(I posted this in the "Geeks Lounge" but didn't get any responses - maybe there'll be better luck here?)
Hi all,
I was wondering if anyone one could point me to (if they exist) some places to nominate people for enormous contributions to open source and open source philosophy? There are a few people that I have seen almost single handedly maintaining some enormous projects and I'd like to give them something more than my personal "good job" email!
I found Google-O'Reilly Open Source Awards, but that was about all I could come up with. Are there others?
Thanks,
Dave
One thing I see is that you are not checking the bounds of the movement - i.e.
void movedown(int x, int y)
{
x = x;
y = y + 1;
};
Should be something like:
void movedown(int x, int y)
{
// x = x; //this line doesn't do anything, so it can be removed.
if(y < maxY)
{
y = y + 1;
}
};
Once you fix those, can you use a debugger to step though the code and tell us when the error occurs and what the error says?
Good luck,
Dave
Sure, just set a member variable before your destructor gets called, and reference that variable from the destructor.
Dave
I think you need an asynchronous timer as you will need to continue entering numbers while keeping track of the time. Boost has one:
http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/tutorial/tuttimer2.html
Here is the algorithm - it is actually quite short and straight forward:
http://en.wikipedia.org/wiki/Breadth-first_search#Algorithm_.28informal.29
There are a couple of non-exhaustive search ideas here:
http://www.experts-exchange.com/Programming/Algorithms/Q_23060580.html
They seem to be based mainly on two facts: 1) the board fills from the bottom, so there should be many solutions involving the top of the board that are not possible and 2) for the rows, if you haven't found a solution after the first 5, you know for sure if you will be able to find a solution by looking at the next two.
Good luck,
Dave
You're going to have to try it yourself first! Give it your best shot and let us know if you run into any particular questions.
Dave
Ah I didn't realize that - is this basically to keep threads linear?
Is there a way to edit a post? I think there used to be, right? I don't see an edit button anymore :(
It definitely will NOT work with different cases. It would only think the element already exists if EXACTLY that element exists.
So if you have already added "dog", and then you try to add "Dog", you will now have BOTH "dog" AND "Dog" in the set.
Dave
I don't know what you mean by "wacky casing", but correct, it does all of the checking for you. insert() just does nothing if the element already exists.
This compiles fine for me:
#include <iostream>
#include <vector>
#include <algorithm>
int main(int argc, char* argv[])
{
std::vector<unsigned int> V(10);
for(unsigned int i = 0; i < 10; i++)
{
V[i] = 10*i;
std::cout << V[i] << " ";
}
std::cout << std::endl;
std::vector<unsigned int>::iterator it = find(V.begin(), V.end(), 70);
if(it == V.end())
{
std::cout << "Could not find 70 in the vector" << std::endl;
}
else
{
std::cout << "The number 70 is located at index " << it - V.begin() << std::endl;
}
return 0;
}
As Narue recommended, std::set is a container which holds only unique elements.
#include <set>
std::set<unsigned int> S;
for(unsigned int i = 0; i < 10; i++)
{
S.insert(i);
}
http://www.cppreference.com/wiki/stl/set/start
Dave
Ah, I forgot to tell you to
#include <algorithm>
Narue is right, but if you do want to use a vector for some reason, std::vector has a find() function that does exactly what you're looking for. Here is the example I have:
void TestFind()
{
std::vector<unsigned int> V(10);
for(unsigned int i = 0; i < 10; i++)
{
V[i] = 10*i;
std::cout << V[i] << " ";
}
std::cout << std::endl;
std::vector<unsigned int>::iterator it = find(V.begin(), V.end(), 70);
if(it == V.end())
{
std::cout << "Could not find 70 in the vector" << std::endl;
}
else
{
std::cout << "The number 70 is located at index " << it - V.begin() << std::endl;
}
}
Hope that helps,
Dave
Like I said, writing to the file is the first step. The second step is then reading the file and parsing it so you can get the MAC address as a string. Then you can do whatever you want with it. Am I missing a requirement?
Surely there are better solutions, but here is an easy one:
Use the system() function to run "ifconfig > file.txt". Then load this file using ifstream and parse it to get the string after HWaddr. This is your mac address.
Dave
Should this be posted under code snippets or something? There's not really a question is there?
Dave
You want to get your MAC address in c++?
What is the error? Why don't you put a statement to check the length in all of the queue addition/removal functions. This should help you track down the problem.
Also, why did you post this twice?
Dave
Thanks thelamb, that is exactly the behavior I am going for. However, I guess an important part that I failed to mention is that I'm working inside of a library where I cannot change PersonClass (clearly this is all an example, but the equivalent class in the library). Is there any decent way to do it without doing what thelamb suggested?
Thanks,
Dave
I'm having a bit of trouble with dynamic_casting. I need to determine at runtime the type of an object. Here is a demo:
#include <iostream>
#include <string>
class PersonClass
{
public:
std::string Name;
virtual void test(){}; //it is annoying that this has to be here...
};
class LawyerClass : public PersonClass
{
public:
void GoToCourt(){};
};
class DoctorClass : public PersonClass
{
public:
void GoToSurgery(){};
};
int main(int argc, char *argv[])
{
PersonClass* person = new PersonClass;
if(true)
{
person = dynamic_cast<LawyerClass*>(person);
}
else
{
person = dynamic_cast<DoctorClass*>(person);
}
person->GoToCourt();
return 0;
}
I would like to do the above. The only legal way I found to do it is to define all of the objects before hand:
PersonClass* person = new PersonClass;
LawyerClass* lawyer;
DoctorClass* doctor;
if(true)
{
lawyer = dynamic_cast<LawyerClass*>(person);
}
else
{
doctor = dynamic_cast<DoctorClass*>(person);
}
if(true)
{
lawyer->GoToCourt();
}
The main problem with this (besides having to define a bunch of objects that won't be use) is that I have to change the name of the 'person' variable. Is there a better way?
Thanks,
Dave
If you are interested in comparisons, Boost has Bessel functions:
Dave
I don't know about the "Chinese" characters, but it should be reasonably easy to fix the message box program. What I would suggest is making a < 20 line (or as small as possible) program that simply tries to display a message box. That should be easily debug-able by someone here. Unfortunately I'm not a Microsoft C guy so I can't help directly.
Also, you should really use a descriptive title to identify your question to the community. "Help me!" is not very useful :)
Dave
I don't understand? It looks like you have working timer code - so just put it wherever you want the timer to happen in the real program, right?
Dave
What is the problem? Please try to narrow down the problem to a < 20 line compilable example that we can help you with.
Dave
Here is an example of how to use strncpy:
http://www.cplusplus.com/reference/clibrary/cstring/strncpy/
I strongly suggest that you try little < 10 line demonstration programs, ensure you know how everything works, and THEN write a 300 line program. It will work out much better for you, I am sure. It will also help us help you because then we will have a manageable piece of code to help you with.
Dave
NathanOliver - it doesn't seem to like comparing a string to a character - could you have meant word!="\0"
? When I did that, it still did not skip the blank line.
Dave
What you did will do exactly what my "continue" did, it is like a double-negative :)
However, it isn't working for me either - I guess this is not how you are supposed to check for newlines? Someone else will fix my mistake soon :)