Guys, guys, let's try to use real English words please!
The title "Help plsssssssssss", the lack of capitalization, the "help plss" and "ur probelm wil b solve" make the forum look very unprofessional!
David
Guys, guys, let's try to use real English words please!
The title "Help plsssssssssss", the lack of capitalization, the "help plss" and "ur probelm wil b solve" make the forum look very unprofessional!
David
alex,
Us telling you exactly where to put each character is not helpful for anyone involved. I'd suggest finding a basic c++ tutorial dealing with functions, arguments, and parameters. Compiling a few basic things and playing with them will help you get a handle on things. Then we can return to your vector question if you still have a problem.
David
Looks good. You just have to get the Map variable into the draw_map function.
std::vector<std::vector<int> > yourGrid;
msize(3,3,yourGrid);
You get to do
yourMap[i][j] = an int;
(Just like a 2d array)
@madhub2v - please use real English words. "Thank Q" is not a word.
@apee_mimi - Welcome to DaniWeb! You have done what we call "thread hijacking". That is, you've asked a question unrelated to the original post at the bottom of a thread. You should, instead, start your own thread.
David
Are you looking for QValueList? There is an example here: http://doc.qt.nokia.com/3.3/qvaluelist.html
I didn't see this post before responding in your other post.
I'd recommend using a std::vector<std::vector<int> > . You can then resize on the fly.
(not tested... just a guideline)
void msize(int Height,int Width, std::vector<std::vector<int> > map)
{
map.resize(width); // you'll have to pick if the outer vector or the inner vectors are the rows or cols
for(unsigned int i = 0; i < map.size(); i++)
{
map[i].resize(height);
}
}
David
What is the problem? I'd recommend using a std::vector<std::vector<int> > . You can then resize on the fly.
Naming the variables the letter names doesn't really help anything. I would create a vector of pairs: std::vector<std::pair<char, int> > or something like that to keep the letters attached to their current value. I don't know what you're doing with all of the multiplying by 4 and modding by 10 business? (Comment, comment, comment!) You also haven't showed how the input is provided? It it that string? (TOO + ... )? If so, you'll first have to parse and figure out where the + symbols are. Then you can convert the individual "words" to numbers by doing string "find and replace" (http://www.java2s.com/Code/Cpp/Data-Type/StringFindandreplace.htm) then you can convert to an int using a stringstream: http://programmingexamples.net/index.php?title=CPP/StringStream
Phew, looks like you've got a lot of work to do! Good luck!
David
This will show you how to iterate through an std::list. I don't know about qtlist - if you can send a link to the documentation or something maybe someone can help if you have trouble with that part.
You may want to look into the "system" command. I don't know if it works in windows.
That looks fine to me - doesn't this do what you want? http://programmingexamples.net/index.php?title=CPP/ZeroPad
namra_shahid, what you have done here is called "thread hijacking". Please start your own tread rather than post a question at the bottom of someone elses!
Thanks,
David
1) Instead of
if (convert_code == "f")
{
c_f_fraction();
}
you'd want to do:
main()
{
if (convert_code == "f")
{
std::cout << "\nPlease input the numerator of the fraction you wish to convert.<#/help> ";
std::cin >> numerator;
std::cout << "\nPlease input the denominator of the fraction you wish to convert.<#/help> ";
std::cin >> denominator;
c_f_fraction(numerator, denominator);
}
}
double c_f_fraction(double numerator, double denominator)
{
// your logic here (something like return numerator/denominator;
}
See what I mean? This way the function is much more reusable (if you read numbers from a file, or generated them manually, you can still convert them (rather than relying on user input to happen in every instance).
3) The idea is "documentation by good code writing". The problem is that you have to assume programmers will not keep the documentation up to date (that is, they will change the code but forget to update the documentation). So,you have to train them to write the code in such a way that it is "self documenting". The use of intelligible variable names is a good start.
Why are you reading them as ints? You should change:
int user;
int password;
to
std::string user;
std::string password;
and
if (user1 == user)
to
if (user1.compare(user) == 0)
This is pretty much c not c++. You could post in the C forum, or you could use c++.
Also, please do not post line numbers in your code, the code tag adds the line numbers for you.
Defines:
#define MAX 100
should be replaced with
unsigned int MAX = 100;
(or better yet, don't use global variables at all!)
You could use an std::string:
std::string msg1;
instead of a char array:
char msg1[MAX];
You should use std::cout instead of printf.
You should use cin instead of getchar.
You should use std::string::compare instead of strcmp.
Good luck!
David
A few comments:
1) You should handle all of the user input directly in main and then pass values to the functions (rather than call the functions with no arguments and do the input inside as you have done).
2) Rather than have a conversion from each type to every other one (imagine how complicated this would get if there were 10 types instead of 3!), I would always convert to a "common" format (say always to decimal). Then you can have a single function for each type to convert from the common type. You will then have ~2N functions vs ~N^2 (where N is the number of types)
3) Use descriptive variable and function names! c_f_fraction_1 is not obvious to a first time reader of the code.
Good luck,
David
I think it is because your declaration does not take the variables by reference.
Try changing
void reshuffle (std::string::size_type,std::string::size_type,std::string);
to
void reshuffle (std::string::size_type&,std::string::size_type&,std::string&);
Please fix your indentation, it is crazy!
Also, we may need to see the contents of CAMERA.h
The ifstream should automatically parse on white space. That is:
dataFIle >> user >> password;
should do the trick.
I don't know how to compare char arrays, I've never tried :)
std::vector<std::string>
If you used std::string instead of char arrays, you could use the .Compare function: http://programmingexamples.net/index.php?title=CPP/Strings/Compare
1) Please use code tags when posting code - it makes it much easier for us to read.
2) I suggest you "break out" the problem. That is, create a new program that sets up some hard coded values and tries to do the computation. You should then have only a few lines to deal with and will likely be able to find the problem. If not, you can ask us and we only have to look at the few relevant lines rather than wondering if there is a problem with your input routines, etc.
David
You have declared tokens as a pointer to a vector:
std::vector<char*>* tokens
But are then trying to access the size() function as if it is an object (with the '.' operator):
tokens.size()
You need to instead use the -> operator:
tokens->size()
You also have to use
(*tokens)[i]
instead of
tokens[i]
David
So there is no reason to "absolutely not", right - you're saying it's not wrong, just maybe not necessary? I would imagine many compiler will still complain that main doesn't return a value - but maybe I am wrong?
Bah, turns out cap was NAN! So annoying...
I don't know that this makes it much clearer, but stated another way:
double cap = some value...
assert(cap >= 0);
The assert is triggered.
double cap = same value as above
if(cap < 0)
{
exit(-1);
}
I thought this would behave identically to the assert (it would quit if cap is < 0), but the assert fails at times when the if statement doesn't.
Can anyone explain why this would fail:
assert(cap >= 0);
But this passes?
if(cap < 0)
{
exit(-1);
}
That is, the assert is triggered, but if I replace it with conditional, the exit() function is never called.
Thoughts?
Thanks,
David
You need to put single quotes around the letters
Change if (ch1 == a)
to if (ch1 == 'a')
You should also return 0;
at the end of main(). You should also have an else
statement to help catch things like this :)
Hope that helps,
David
I really suggest abstracting the problem. Rather than posting 300 lines of code, 290 of which have nothing to do with the operator you are trying to overload, you should be able to make a <20 line program that overload the operator. If doing that alone doesn't help you solve your problem, it will be much easier for us to spot the error :)
David
So you'll want to write a "DrawMap" function that first clears the screen and then writes the | and - (the things for the snake to run into0 and draws the snake's position (using 0's or something). This is quite a big project to just ask "How do I do it?". You should come up with a plan of what you think you need to do and we can check it for you.
David
You'll first have to decide what kind of GUI you want. I.e. do you want to use OpenGL, etc?
Please mark the thread as solved if you're all set.
Again, you're going to have to be much more specific if you want us to help!
I didn't jump to conclusions. I read the 1 line about your question and then answered it. Then I saw your 800 lines of code and thought that it belonged in the code snippets section.
You can't put a semicolon at the end if the "if" line. Google should know about plenty of tutorials to get you started.
GLUT is a layer on top of OpenGL - http://www.opengl.org/resources/libraries/glut/
If you just want to post code an don't have a question about it, I'd put it here: http://www.daniweb.com/code/forum8.html
Please use code tags when you post code. Also, please include the compiler output. "It said something is wrong" is pretty hard for us to debug!
Just store the words in a std::vector<std::string>
and then output the appropriate word with std::cout << words[i];
. You could alternatively use a switch
statement.
In the future, please use more descriptive thread titles!
David
Please make your thread titles more descriptive!
Please use real English words (e.g. 'you' instead of 'u').
I'm not a Windows guy, but when your IDE produces a 'win32 app' I believe it is just including "windows.h" and the like so you can do some basic GUI stuff.
David
That code doesn't compile for me. 'receive' is a member variable of 'bank' and you're not addressing it as such. You also need a semicolon after the class definition.
If you can get the whole input, then put it into a std::stringstream and you can use the >> operator just like you would with an fstream.
Lerner - I think he just means to paste something into the console window and then press enter, just as if he had typed it in the window directly.
David
This is some fancy footwork with some STL stuff, but it does the trick:
http://programmingexamples.net/index.php?title=CPP/Strings/Split
Basically you are trying to separate the paragraph by the ' ' character (a space). Then you can store each word in a std::vector<std::string>
and then use yourVector.size()
to get a count of the words.
You should read every line like this:
http://programmingexamples.net/index.php?title=CPP/IO/ReadingLines
Then you can use the "SplitOnDelim" idea from here:
http://programmingexamples.net/index.php?title=CPP/Strings/Split
(either once, or twice). If you store everything in a std::vector<std::string>
it should be really easy to do something specific to the first element and something different to the rest.
Good luck,
David
Since the solutions will not all have the same number of coins, I recommend you use a std::vector<std::vector<int> >
. Can you enumerate an example input, the current output, and the expected output for us?
Can you explain what the problem is? What is an example input, current output, and the expected output?
David
I don't know anything about CURL, but you can use SQL through VTK:
http://vtk.org/Wiki/VTK/Examples/Cxx#Databases