daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

Looks good. You just have to get the Map variable into the draw_map function.

daviddoria 334 Posting Virtuoso Featured Poster
std::vector<std::vector<int> > yourGrid;
msize(3,3,yourGrid);
daviddoria 334 Posting Virtuoso Featured Poster

You get to do

yourMap[i][j] = an int;

(Just like a 2d array)

daviddoria 334 Posting Virtuoso Featured Poster

@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

daviddoria 334 Posting Virtuoso Featured Poster

Are you looking for QValueList? There is an example here: http://doc.qt.nokia.com/3.3/qvaluelist.html

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

What is the problem? I'd recommend using a std::vector<std::vector<int> > . You can then resize on the fly.

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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.

daviddoria 334 Posting Virtuoso Featured Poster

You may want to look into the "system" command. I don't know if it works in windows.

daviddoria 334 Posting Virtuoso Featured Poster

That looks fine to me - doesn't this do what you want? http://programmingexamples.net/index.php?title=CPP/ZeroPad

daviddoria 334 Posting Virtuoso Featured Poster

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

Fbody commented: Amen :) +3
daviddoria 334 Posting Virtuoso Featured Poster

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.

daviddoria 334 Posting Virtuoso Featured Poster

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)
daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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&);
daviddoria 334 Posting Virtuoso Featured Poster

Please fix your indentation, it is crazy!

Also, we may need to see the contents of CAMERA.h

daviddoria 334 Posting Virtuoso Featured Poster

The ifstream should automatically parse on white space. That is:

dataFIle >> user >> password;

should do the trick.

daviddoria 334 Posting Virtuoso Featured Poster

I don't know how to compare char arrays, I've never tried :)

std::vector<std::string>
daviddoria 334 Posting Virtuoso Featured Poster

If you used std::string instead of char arrays, you could use the .Compare function: http://programmingexamples.net/index.php?title=CPP/Strings/Compare

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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

nirali7 commented: thnks a ton... :) +0
daviddoria 334 Posting Virtuoso Featured Poster

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?

daviddoria 334 Posting Virtuoso Featured Poster

Bah, turns out cap was NAN! So annoying...

daviddoria 334 Posting Virtuoso Featured Poster

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.

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

You'll first have to decide what kind of GUI you want. I.e. do you want to use OpenGL, etc?

daviddoria 334 Posting Virtuoso Featured Poster

Please mark the thread as solved if you're all set.

daviddoria 334 Posting Virtuoso Featured Poster

Again, you're going to have to be much more specific if you want us to help!

daviddoria 334 Posting Virtuoso Featured Poster

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.

daviddoria 334 Posting Virtuoso Featured Poster

You can't put a semicolon at the end if the "if" line. Google should know about plenty of tutorials to get you started.

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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!

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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.

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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.

cpeepee commented: thank you very much! +0
daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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?

daviddoria 334 Posting Virtuoso Featured Poster

Can you explain what the problem is? What is an example input, current output, and the expected output?

David

daviddoria 334 Posting Virtuoso Featured Poster

I think this belongs in the "Looking to hire" section:

http://www.daniweb.com/forums/forum72.html

daviddoria 334 Posting Virtuoso Featured Poster

I don't know anything about CURL, but you can use SQL through VTK:
http://vtk.org/Wiki/VTK/Examples/Cxx#Databases