m4ster_r0shi 142 Posting Whiz in Training

which command were you talking about?

sf::Sprite::setColor

By default it's set to sf::Color(255, 255, 255, 255) (opaque white).
You could set it to sf::Color(i, i, i, 255) and control i with your slidebar.

If this doesn't give you the result you want, I guess you can always try the
'brute force' approach, as ravenous suggests, if you haven't tried it yet.

m4ster_r0shi 142 Posting Whiz in Training

I'm pretty sure the library the OP is using (OpenCV, I presume by looking at some of his/her recent posts) takes care of that.

m4ster_r0shi 142 Posting Whiz in Training

If you use SFML, you can load your image in a sf::Image, then create a sf::Sprite using that image and play with the sprite's color property to adjust the brightness. It's a O(1) operation and it affects every pixel of your image. Maybe the library you're using also has a similar feature and you're not aware of it yet.

m4ster_r0shi 142 Posting Whiz in Training

I was thinking about somehow using a static member that all the matrix cells will be defined by their value + the static value.

This is a very interesting idea. It also is easily generalized. You could have a stack of (different) operations and apply them in order when you want to get the value of a specific element. When you want to set the value of a specific element, you'd have to go backwards and also use the inverse operations. However, that would add a small overhead to every Get / Set call that could quickly become very big (if you keep stacking operations). To solve this problem, you could perform a small number of calculations each time you Get / Set some element. You'd need to also keep track of how many elements you have calculated.

The bottom line is that, while, in the end, you have to make all the calculations, this trick allows very good real time responsiveness for even humongous arrays.

Here's a minimal example.

m4ster_r0shi 142 Posting Whiz in Training

Looks like Perl to me.

m4ster_r0shi 142 Posting Whiz in Training

Or better yet, vectors, since the number of lines in the file is not known during compilation.

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    ifstream fin("main.cpp");

    vector<string> lines;

    string curLine;

    while (getline(fin, curLine)) lines.push_back(curLine);

    for (size_t i = 0, size = lines.size(); i < size; ++ i)
        cout << lines[i] << endl;
}
m4ster_r0shi 142 Posting Whiz in Training

Sorry, I was wrong. Looking more closely, your code doesn't have the problem I thought it had. This problem only arises when you use random_shuffle carelessly (as I deliberately did in my second example). So, your code that uses std::set is fine.

To make amends for my mistake, let me answer some of your questions.

And also most of the time the four numbers starts with a 0 even there's no 0 value in the array.

There are several zero values in your array :) Check this out:

#include <iostream>

using namespace std;

int main()
{
    int array[3][3] = {
        { 1, 2, 3 },
        { 4, 5 },
        { 6 }
    };

    for (int i = 0; i < 3; ++ i)
    {
        for (int j = 0; j < 3; ++ j)
            cout << array[i][j];

        cout << endl;
    }
}

What's the difference between the two version?

The difference is that the while loop runs as many times as needed to fill the set with four (different) numbers, while the for loop always runs four times. After these four runs, the set may have four (different) values, but it may also have only three or two or even one. Take a look at std::set and how it works.

Also, I want to add here that your code relies on value uniqueness, while the examples I posted rely on index uniqueness. This difference is irrelevant to the method used to get …

m4ster_r0shi 142 Posting Whiz in Training

There is a problem with the logic you use to generate the random indexes.

Let's start with something simpler. Suppose you want to get three unique random values from a unidimensional array of four elements. The easiest way to do this is by using random_shuffle:

#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>

using namespace std;

int main()
{
    srand(time(0));

    string value_array[4] = { "one", "two", "three", "four" };

    int index_array[4] = { 0, 1, 2, 3 };

    random_shuffle(index_array, index_array + 4);

    for (int i = 0; i < 3; ++ i)
        cout << value_array[index_array[i]] << endl;
}

Now, there are two ways to scale this in order to accommodate for bidimensional arrays. One of them is wrong (and is very similar to what you're doing) and the other is right. Let's see the wrong way first:

#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>

using namespace std;

int main()
{
    srand(time(0));

    string value_array[3][4] = {
        { "one-a", "two-a", "three-a", "four-a" },
        { "one-b", "two-b", "three-b", "four-b" },
        { "one-c", "two-c", "three-c", "four-c" }
    };

    int index_array_a[3] = { 0, 1, 2 };
    int index_array_b[4] = { 0, 1, 2, 3 };

    random_shuffle(index_array_a, index_array_a + 3);
    random_shuffle(index_array_b, index_array_b + 4);

    for (int i = 0; i < 3; ++ i)
        cout << value_array[index_array_a[i]][index_array_b[i]] << endl;
}

One problem with this is that it just doesn't work if the number of your picks is bigger than the smallest dimension.

But the real problem is that …

m4ster_r0shi 142 Posting Whiz in Training

i couldnt even get SFML to install right or work with code blocks....i think im gonna pass.

Don't give up so easily. Since you're using Code::Blocks, my guess is that you don't have the correct version of MinGW.

Here's what you'll do:

  1. Get the latest MinGW from here (use the GUI installer), and install the C and C++ compilers in C:\MinGW.

  2. Open Code::Blocks and from the menu bar go Settings -> Compiler and debugger...

  3. Go to the Toolchain executables tab and change the compiler directory from
    C:\Program Files\CodeBlocks\MinGW (or whatever it currently is) to C:\MinGW.

Now, you should be able to make SFML 1.6 work by following these instructions.

If you face any problems don't hesitate to post.

m4ster_r0shi 142 Posting Whiz in Training

Just let the OP do what he feels he wants to next.

I have no intention of doing otherwise. Actually, even if I had the intention, I wouldn't be able to do it. The OP can do whatever (s)he wants regardless of what I say. However, doing something because you want to do it is not the same as doing something because you think is right or / and easy while in fact is not.

If the OP had said that (s)he wants to remain in the console because (s)he really likes its vertical scrolling bar and the grey characters on the black background, I wouldn't have a reason to continue. It's his / her personal preference and I respect that. But (s)he didn't say that. (s)he said that (paraphrased) most programmers use the console to write real games because it's easy.

As someone who has more (not much more though) experience than the OP in the topic, I feel obliged to present the alternatives and make sure (s)he understands which one is better in what way and why. But after that, of course, the OP can do anything (s)he desires.

I didn't have any intention to upset you (or anyone else), and I apologize if I did.

m4ster_r0shi 142 Posting Whiz in Training

Now masterroshi kindly posted a starter template for tic-tac-toe.

That code is completely broken though :S I was in a hurry when I wrote it and when I realized there were problems it was too late to edit my post. So, here's a fixed version, in case the OP decides to use it:

#include <iostream>

void drawGrid(int grid[3][3])
{
    std::cout << std::endl;

    for (int i = 0; i < 3; ++i)
    {
        if (i != 0) std::cout << "------" << std::endl;

        for (int j = 0; j < 3; ++j)
        {
            char ch;

            switch (grid[i][j])
            {
                case 0 : ch = ' '; break;
                case 1 : ch = 'X'; break;
                case 2 : ch = 'O';
            }

            if (j != 0) std::cout << '|';

            std::cout << ch;
        }

        std::cout << std::endl;
    }

    std::cout << std::endl;
}

int main()
{
    int grid[3][3] =
    {
        {0, 0, 1},
        {0, 1, 0},
        {2, 0, 0}
    };

    while (true)
    {
        // add more stuff here...

        drawGrid(grid);

        // add more stuff here...

        std::cout << "quit? (y/n) ";

        char ch;

        std::cin >> ch;

        if (ch == 'y' || ch == 'Y') break;
    }

    return 0;
}

I still insist on using a finite state machine instead of a flowchart to model the game logic though.

I quote from here:

...some people do not see the true difference between the two. The confusion starts with the missing understanding of a state which is not known in a flowcharts. [...]

m4ster_r0shi 142 Posting Whiz in Training

Because i personally think my first real game should be in the CP because thats what most programmers do.

One problematic thing with this line of reasoning is that 'real games' and 'CP' have nothing to do with each other. Another is that what most beginner (<- you forgot that adjective above) programmers do is not what is right.

And for obvious reasons, like, it being more simple and Programmer-Friendly. :)

This statement is just plain wrong. The console is actually a very hostile environment for game development. I think you didn't check the first link I posted, so, you'd better do it now.

ive never thought of writing a flowchart. i think i might do that.

Don't do it. A flowchart is not the best technique to use when designing a game. It may be enough for something simple as tic-tac-toe, but it scales very poorly as you move to bigger and more complex games. When designing a game, it's better to think in terms of state and events that affect that state. For example, ask yourself questions like:

  1. "What are the different game states I'll have to deal with?"

  2. "In what way exactly can the user interact with the game in each state?"

  3. "What are the events (either user or game generated) that trigger state transitions?"

And then answer these questions:

  1. "There will be an initialization state, where the user chooses whether (s)he will play against the computer or …

m4ster_r0shi 142 Posting Whiz in Training

i dont want to jump into graphics yet

Why is that?

So, what kind of game do you want to make?

PS: Something I found regarding your original question
("how hard would it be to make a text-based zork-like game?")

m4ster_r0shi 142 Posting Whiz in Training

We don't know what OS the OP is using. Yes this matters, linux or Mac users will normally find using 3rd party libraries slightly more tricky.

Ok. But if you are a linux user you might actually find this fun :) Plus, it will only be difficult the first time you'll do it. Oh, and the key word here is 'slightly'.

We don't know what IDE the OP is using. Yes this matters, because where do you put the directory, do you have to add compiler/linking switches? All this makes it much more difficult.

No, it doesn't make it much more difficult. You are nitpicking now.

How you can just brush it off 'as a very poor argument' without no reasons for justification? Now the OP not only has to learn the semantics of another library but also OOP idioms.

Huh? I think you missed my point above. Read it again, more carefully. All I said was that introducing graphics doesn't have to introduce OOP. You can use CSFML or SDL and leave OOP out if you find it confusing.

Again, sorry but have to disagree here. You can adequately write a console version of tic-tac-toe without knowing how to use graphics.

Again, you missed the point. Let me restate it: The language features you need in order to write a console version of tic-tac-toe are the same language features you need in order to write a tic-tac-toe game with graphics. If …

m4ster_r0shi 142 Posting Whiz in Training

After only 1 week, you don't have the background in the language to even think about graphics yet. Learn the language first. Graphics can come later.

This doesn't really make sense, because modern graphics libraries render language knowledge and graphics orthogonal concepts.

Suppose you want to write a Tic-Tac-Toe game. In console, you would do something like this:

#include <iostream>

void drawGrid()
{
    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            char ch;

            switch (grid[i][j])
            {
                case 0 : ch = ' '; break;
                case 1 : ch = 'X'; break;
                case 2 : ch = 'O';
            }

            std::cout << ch;
        }

        std::cout << endl;
    }
}

int main()
{
    int grid[3][3];

    while ( /* user doesn't want to quit */ )
    {
        // do some stuff...

        drawGrid();

        // do some more stuff...
    }
}

Using SFML, you would do something like this:

#include <SFML/Graphics.hpp>

void drawGrid(sf::RenderWindow & window, sf::Sprite & sptX, sf::Sprite & sptO)
{
    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            switch (grid[i][j])
            {
                case 1 : sptX.SetPosition(i * BLOCK_SIZE, j * BLOCK_SIZE);
                         window.Draw(sptX); break;
                case 1 : sptO.SetPosition(i * BLOCK_SIZE, j * BLOCK_SIZE);
                         window.Draw(sptO);
            }
        }
    }
}

int main()
{
    int grid[3][3];

    sf::Image imgX, imgO;

    imgX.LoadFromFile("X.png");
    imgO.LoadFromFile("X.png");

    sf::Sprite sptX(imgX), sptO(imgO);

    sf::RenderWindow window(/* window params (e.g. resolution) */);

    while ( /* user doesn't want to quit */ …
m4ster_r0shi 142 Posting Whiz in Training

im thinking of a game in the Command Prompt

Read this first.

IMO, the thing with the best result-to-effort ratio you can do right now is grabbing a graphics library (e.g. SFML) and writing a simple scrolling shooter. And if you 're worrying about your artistic skills, don't. Computer software nowadays allows you to create really cool stuff without a lot of effort. I'm working on a 2D puzzle game myself, and, recently, I remade the graphics using Blender. You can see the result here (I also put the previous version for comparison).

m4ster_r0shi 142 Posting Whiz in Training

Here's an idea:

#include <iostream>
#include <string>

template <class A, class B> struct SameType { static const bool Result = false; };
template <class A> struct SameType <A, A>   { static const bool Result = true;  };

template <bool C, class True, class False> struct IfThenElse;
template <class True, class False> struct IfThenElse <true,  True, False> { typedef True  Result; };
template <class True, class False> struct IfThenElse <false, True, False> { typedef False Result; };

template <class T>
struct MyClass
{
    struct DoItStr  { void operator()() { std::cout << "std::string stuff..." << std::endl; } };
    struct DoItChar { void operator()() { std::cout << "char stuff..."        << std::endl; } };
    struct DontDoIt { void operator()(); /* using this will trigger a compilation error ;) */ };

    void doIt()
    {
        typedef typename IfThenElse <SameType<T, std::string>::Result, DoItStr,  DontDoIt>::Result DoIt_;
        typedef typename IfThenElse <SameType<T, char>::Result,        DoItChar, DoIt_   >::Result DoIt;

        DoIt()();
    }
};

int main()
{
    // MyClass<int>().doIt(); // uncomment to get an error
    MyClass<char>().doIt();
    // MyClass<double>().doIt(); // uncomment to get an error
    MyClass<std::string>().doIt();

    std::cin.get();
}

Ok, I think I'm done editing...

m4ster_r0shi 142 Posting Whiz in Training

Based on his actual problem statement, it looks like buffered input is his problem. Maybe his description was still ambiguous and confusing since it wasn't a linear description of the problem -- or was it?.

Did anybody else read this several times trying to make sense out of it, or should I feel bad about myself?

WaltP commented: Probably not, and no you shouldn't. If you wish to do that much work, go for it. I want a clear explanation. +14
Lucaci Andrew commented: Nah, that was the problem. +0
m4ster_r0shi 142 Posting Whiz in Training

You are missing endl or flush at the end of most of your output statements.

This is a joke, right? It has to be a joke, because neither is it true nor does it have anything to do with the OP's problem.

The OP's problem arises from mixing istream::operator >> with getline calls, and it's another very common mistake among beginners. The solution is to either use only one or the other, or make sure you clear the buffer from any leftovers of the one before using the other.

Here's an example that demonstrates the problem and an easy fix:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string name;
    string color;

    cout << "Enter your name (one word): ";
    cin >> name;

    cout << "Enter your favourite color (e.g. light blue): ";
    //{ string temp; getline(cin, temp); } // uncomment to fix
    getline(cin, color);

    cout << "Hello, " << name << "!" << endl;
    cout << "Your favourite color is " << color << endl;

    cin.get();
}
m4ster_r0shi 142 Posting Whiz in Training

Judging by the way you use getline, teamnamesquestion must be a char array. The problem with this is that teamnamesquestion == "no" performs a pointer equality check, that will, obviously, always return false.

If you don't believe me, try this:

#include <iostream>

using namespace std;

int main()
{
    char str[10];

    cin.getline(str, 5);

    if (str !=  "no") cout << "foo" << endl;
    if (str != "yes") cout << "bar" << endl;

    std::cin.get();
}

What you can do is either use strcmp instead of the == operator...

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    char str[10];

    cin.getline(str, 5);

    if (strcmp(str,  "no") == 0) cout << "foo" << endl;
    if (strcmp(str, "yes") == 0) cout << "bar" << endl;

    std::cin.get();
}

...or use a std::string instead of a char array, as lucaciandrew suggested...

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str;

    getline(cin, str);

    if (str ==  "no") cout << "foo" << endl;
    if (str == "yes") cout << "bar" << endl;

    std::cin.get();
}
m4ster_r0shi 142 Posting Whiz in Training

Well, you do initialize your globals in globals.h. You shouldn't be doing this. Also, you forgot some const qualifiers in your main.cpp. Read the relevant post of mine in the previous page again, more carefully this time :P

m4ster_r0shi 142 Posting Whiz in Training

Post your code. Post the relevant first lines of globals.h, main.cpp and playa.cpp.

m4ster_r0shi 142 Posting Whiz in Training

I want to clarify something to avoid a potential misunderstanding. JasonHippy's suggestion creates a different set of globals for each module the global header is included in. This, obviously, works fine if you only want global constants. But if you want global variables, it's not enough, as you'll probably want modifications made to a particular global variable in one module to be reflected in every other module. This is why you have to use extern.

m4ster_r0shi 142 Posting Whiz in Training

Personally I'd avoid using extern and just stick them in a header which can be included in any modules that require them.

Er... That's what I suggested too. And you can't do that without extern, to the best of my knowledge.

About the problem, now:

 extern const int SCREEN_WIDTH = 640;
 extern const int SCREEN_HEIGHT = 480;
 extern const int SQUARE_HEIGHT = 22;
 extern const int SQUARE_WIDTH = 10;
 extern SDL_Surface *image = NULL;
 extern SDL_Event event; 

Don't do this in globals.h. Do this instead:

 extern const int SCREEN_WIDTH;
 extern const int SCREEN_HEIGHT;
 extern const int SQUARE_HEIGHT;
 extern const int SQUARE_WIDTH;
 extern SDL_Surface *image;
 extern SDL_Event event;

Notice that I don't initialize them here. This should be done in main.cpp:

 const int SCREEN_WIDTH = 640;
 const int SCREEN_HEIGHT = 480;
 const int SQUARE_HEIGHT = 22;
 const int SQUARE_WIDTH = 10;
 SDL_Surface *image = NULL;
 SDL_Event event;
m4ster_r0shi 142 Posting Whiz in Training

What global variables did you get this error for? How / where do you define these variables? Did you read the link I mentioned above?

m4ster_r0shi 142 Posting Whiz in Training

It looks like you have to include the appropriate SDL headers in playa.cpp. What are the headers (*.h files) that you include in main? Try including them in playa.cpp too. Also, it looks like you have some global variables (e.g. event). Reading this could help. Though, you should try to minimize the use of global variables in your programs.

m4ster_r0shi 142 Posting Whiz in Training

there are certain functions in playa.cpp that require defined things in main.cpp

You mean global variables or other functions? If it's the former, you could modify the functions in playa.cpp to accept these things as arguments. If it's the latter, you could add declarations for these functions at the beginning of playa.cpp.

m4ster_r0shi 142 Posting Whiz in Training

I added the return NULL, but I got the same error

Hmmm... I don't know then. It looks ok to me. Maybe I'm missing something...

I have playa.h and main.cpp included in playa.cpp and playa.h included in main.cpp.

You shouldn't include main.cpp in playa.cpp.

m4ster_r0shi 142 Posting Whiz in Training

Well, the compiler said the problem was with load_image, not load_files. The definition of load_files you post here is irrelevant to the problem.

Now, about the other problems (multiple definition of some functions). Maybe you're declaring and defining these functions in a header file and then include that header file in both main.cpp and playa.cpp. If that's the case, either declare these functions inline or put the definitions in a separate cpp file and see what happens.

m4ster_r0shi 142 Posting Whiz in Training

not all control paths return a value

This means that you have code that looks like this:

ReturnType load_image(ArgType1 arg1, ArgType2 arg2, ...)
{
    //...

    if (some_condition) return something;

    // What happens if some_condition is false?
    // You don't return anything in that case...
}

The first two aren't errors that mess with the program.

While they don't affect compilation, they might seriously mess your program after you manage to compile it :)

m4ster_r0shi 142 Posting Whiz in Training

Obviously, this...

for(int i = 0; i > nrEle ; i++){
    for(int j = 0; j > nrEle; j++){

should be...

for(int i = 0; i < nrEle ; i++){
    for(int j = 0; j < nrEle; j++){
m4ster_r0shi 142 Posting Whiz in Training

I'm not sure how I would check if the values are 'parse-able' or not

You could use a stringstream for that. First, get rid of the trailing whitespace characters in your input. Then, create a stringstream out of your input and use it to set your variable's value. If the operation succeeds and there is no data left in your stringstream object, you're OK.

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

template <class T>
bool TryParse(string input, T & var)
{
    static const string ws(" \t\f\v\n\r");

    size_t pos = input.find_last_not_of(ws);

    if (pos != string::npos)
        input.erase(pos + 1);
    else input.clear();

    stringstream buffer(input);

    return buffer >> var && buffer.eof();
}

int main()
{
    string input;

    int n;
    double d;

    while (cin) // CTRL-Z (or CTRL-D) and enter to quit
    {
        cout << "enter int: "; getline(cin, input);
        if (TryParse(input, n))
            cout << "you entered: " << n << endl;
        else cout << "error" << endl;

        cout << "enter double: "; getline(cin, input);
        if (TryParse(input, d))
            cout << "you entered: " << d << endl;
        else cout << "error" << endl;
    }
}
m4ster_r0shi 142 Posting Whiz in Training

Without optimizations, I get:

0.078 seconds.
0.047 seconds.

With -O3 (best speed optimization) and after
setting numberOfIterations to 1e9 , I get:

0 seconds.
3.297 seconds.

I use the version of mingw that comes along with the latest Code::Blocks.

m4ster_r0shi 142 Posting Whiz in Training

You don't have to call strlen or any other function to compute your word's length.
Notice that, inside your loop, c represents the number of correct consecutive letters.
Just add a bool variable outside your loop and modify it appropriately inside the loop:

bool found = false;

while(true)
{
    if (word[c] == '\0' && ( /* rather verbose condition, involving spaces */ )) { found = true; break; }

    if (para[i] == '\0') break; // found == false

    //...
}
m4ster_r0shi 142 Posting Whiz in Training

I just would like some input/critics/heads up on my class definition and implementation I did for my project.

Looks good. There are a couple of small issues, but other than that looks good. About the small issues now...

Your m_vector doesn't have to be a vector pointer. A vector object would be fine. This would greatly simplify
some things. E.g. your assignment operator (which, by the way, should return a reference) would look like this:

PNVector & PNVector::operator=(const PNVector &other) {
    if (this!= &other)
        this->m_vector = other.m_vector;
    return *this;
}

The rest of your operators could use some const qualifiers.
E.g. PNVector operator+(const PNVector &rhs) [B]const[/B]; Don't forget that at() performs bounds checking, which is unnecessary
in many cases in your code. You could just use operator[] instead.

If you intend to also provide +=, *=, ... etc operators (which is a good idea), you
should implement +, *, ... etc in terms of +=, *=, ... and not the other way around.

I.e. it should look like this:

PNVector & PNVector::operator += (double val)
{
    // ...

    return *this;
}

PNVector PNVector::operator + (double val)
{
    PNVector ret(*this);

    ret += val;

    return ret;
}

Is the only solution to make this work to overload the binary * and / respectively?

Yes. You have to also write global operator overloads (note that both global
and member operators are binary operators, as they accept two arguments).

Finally, note that if …

m4ster_r0shi 142 Posting Whiz in Training

But i dont get it why did i have to put new before and the point is and don't really understand what 'new' does..

Check this out -> http://cplusplus.com/doc/tutorial/dynamic/

i've done these things before without getting any error

Using a pointer without initializing it is undefined behaviour. You simply were lucky :P If you want
to refresh your knowledge on pointers, check this out -> http://cplusplus.com/doc/tutorial/pointers/

m4ster_r0shi 142 Posting Whiz in Training

The problem is that you never create a cs_EnableOverrideAction object in main.
What you create in main is just an uninitialized pointer that could point to anything.

This will work fine -> cs_EnableOverrideAction * enableit = new cs_EnableOverrideAction; This would also work find -> cs_PureFunction * enableit = new cs_EnableOverrideAction; And, of course, if you want to be nice to your OS, you should delete enableit; when you're done with it.

EDIT: Also, in such cases, it's good to make the destructor of your base class virtual, too.

m4ster_r0shi 142 Posting Whiz in Training

I want to do the same thing with a 3D vector. How would the code look?

You can do it like this:

vector<vector<vector<float> > > vec (5, vector<vector<float> > (5, vector<float> (5, 0) ) );

The above creates a 5 x 5 x 5 3D vector, with all initial values set to zero.

How do I index a 3D vector like this?

You can do it like this:

vec.at(1).at(2).at(3) = 5.5;

//or, if you don't want bounds checking...

vec[1][2][3] = 5.5;

However, for performance reasons, it would be better to create
a wrapper around a 1D vector that mimics 3D behaviour, like this:

#include <iostream>
#include <vector>

template <class T>
class Vector3D
{
public:

    Vector3D(unsigned size_i_, unsigned size_j_, unsigned size_k_):
        size_i(size_i_), size_j(size_j_), size_k(size_k_)
        { data.resize(size_i*size_j*size_k); }

    Vector3D(unsigned size_i_, unsigned size_j_, unsigned size_k_, const T & default_value):
        size_i(size_i_), size_j(size_j_), size_k(size_k_)
        { data.assign(size_i*size_j*size_k, default_value); }

    T & operator () (unsigned i, unsigned j, unsigned k)
        { return data[i*size_j*size_k + j*size_k + k]; }

        // or, if you want bounds checking...
        // data.at(i*size_j*size_k + j*size_k + k);

    const T & operator () (unsigned i, unsigned j, unsigned k) const
        { return data[i*size_j*size_k + j*size_k + k]; }

        // or, if you want bounds checking...
        // data.at(i*size_j*size_k + j*size_k + k);

    //...

    // more member functions
    // (e.g. resize etc...)

    //...

private:

    unsigned size_i;
    unsigned size_j;
    unsigned size_k;

    std::vector<T> data;
};

int main()
{
    Vector3D<int> v3d(2,3,4,100);

    v3d(1,2,3) = 0;

    std::cout << v3d(0,1,2) << std::endl;
    std::cout << v3d(1,2,3) << std::endl; …
m4ster_r0shi 142 Posting Whiz in Training

I don't know what you mean by saying "hook", but if you want to hide the console cursor, you can do it like this:

#include <windows.h>
#include <iostream>

int main()
{
    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO cursor_info;

    GetConsoleCursorInfo(console, &cursor_info);

    cursor_info.bVisible = false;

    SetConsoleCursorInfo(console, &cursor_info);

    std::cout << "See? No cursor! -> ";

    Sleep(3000);
}

Useful links:

http://msdn.microsoft.com/en-us/library/ms683163(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms686019(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms682068(v=vs.85).aspx

m4ster_r0shi 142 Posting Whiz in Training

If your answers are like mine ("yes" and "no"), then perhaps you need another approach.

Okay. This will work fine (and I have to put a semicolon at the end, otherwise it won't compile):

#define LOOP_BODY \
do { \
\
    dx =  cos(atan(slope)) * line_length; \
    dy = -sin(atan(slope)) * line_length; \
\
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); \
    MouseMove(dx, dy); \
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); \
\
    Sleep(25); \
} while(0)

What's the next test?

m4ster_r0shi 142 Posting Whiz in Training

How about something less tricky.

I was referring to the algorithm. Tweaking the parameters (slope_max, slope_change and line_length) can
produce interesting results. Making slope_change and line_length variable can also yield very interesting results.

Like for example using a function instead of some hacky multi-line macro.

There's nothing wrong with hacky multi-line macros. On the contrary, they make my code more boost-like :D

m4ster_r0shi 142 Posting Whiz in Training

How about something less tricky. Something like this:

#include <windows.h>
#include <iostream>
#include <cmath>

bool IsPressed(int vkey) { return GetAsyncKeyState(vkey) >> 15; }

void MouseMove(int dx, int dy)
{
    POINT point; GetCursorPos(&point);
    SetCursorPos(point.x + dx, point.y + dy);
}

const double slope_max    = 1.35;
const double slope_change = 0.15;

const double line_length  = 16;

#define LOOP_BODY \
    dx =  cos(atan(slope)) * line_length; \
    dy = -sin(atan(slope)) * line_length; \
\
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); \
    MouseMove(dx, dy); \
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); \
\
    Sleep(25);

int main()
{
    std::cout << "hit F8 to begin" << std::endl;

    while (!IsPressed(VK_F8)) Sleep(25);

    double slope, dx, dy;

    for (slope = 0;           slope < slope_max; slope +=  slope_change) { LOOP_BODY }
    for (slope =  slope_max;  slope > 0;         slope -=  slope_change) { LOOP_BODY }
    for (slope = 0;          -slope < slope_max; slope += -slope_change) { LOOP_BODY }
    for (slope = -slope_max; -slope > 0;         slope -= -slope_change) { LOOP_BODY }
}
sergent commented: Thanks! I don't have time right now, I will try that soon! +4
m4ster_r0shi 142 Posting Whiz in Training

If you want to modify something inside a function, you should pass it by reference ;)
This will work -> void change(float (*[B]&[/B]d)[3], float (*e)[3]) { d = e; }

m4ster_r0shi 142 Posting Whiz in Training

I'm pretty sure the statement updating your population should be -> population *= (1 + annualBirth - annualDeath);

m4ster_r0shi 142 Posting Whiz in Training

Check this out:

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double val_1 = 1.56356;
    double val_2 = 1.56756;

    cout << floor( (val_1 + 0.005) * 100.0 ) / 100.0 << endl;
    cout << floor( (val_2 + 0.005) * 100.0 ) / 100.0 << endl;

    return 0;
}

Useful link -> http://cplusplus.com/reference/clibrary/cmath/floor/

Another way:

#include <iostream>

using namespace std;

int main()
{
    double val_1 = 1.56356;
    double val_2 = 1.56756;

    cout << int( (val_1 + 0.005) * 100.0 ) / 100.0 << endl;
    cout << int( (val_2 + 0.005) * 100.0 ) / 100.0 << endl;

    return 0;
}
m4ster_r0shi 142 Posting Whiz in Training

Are you sure the library doesn't exist in your MinGW folders?

I have the latest version of Code::Blocks/MinGW and I was able
to locate it here -> ...CodeBlocks\MinGW\lib\libpsapi.a See if you can find it, link to it and see if the problem persists.

m4ster_r0shi 142 Posting Whiz in Training

Try this:

//...

string = string.replace('\\', '/'); // replace \ with /
string = string.replace('\"', ' '); // replace " with space
string = string.trim(); // remove leading and trailing spaces

//...
m4ster_r0shi 142 Posting Whiz in Training

Yes, it's a very good start. I like the fact that you noticed that you should print when the letters are different.
Also, even though I like the reputation I got from Narue, I'd like it even more if we could prove her wrong :P
I would do it in a slightly different way, so that I only need to print when the letters are different:

(aa)abbbddccc# don't print

a(aa)bbbddccc# don't print

aa(ab)bbddccc# print 'a'

aaa(bb)bddccc# don't print

aaab(bb)ddccc# don't print

aaabb(bd)dccc# print 'b'

aaabbb(dd)ccc# don't print

aaabbbd(dc)cc# print 'd'

aaabbbdd(cc)c# don't print

aaabbbddc(cc)# don't print

aaabbbddcc(c#) print 'c'

Now, let's try to write a C++ program that does this.

#include <iostream>
using namespace std;

int main()
{
    char my_string[] = "aaabbbddccc#";

    char current_letter;
    char next_letter;

    int i;

    for ( /* ... */ )
    {
        current_letter = //...
        next_letter = //...

        if ( /* current letter is different than next letter */ )
        {
            cout << current_letter;
        }
    }

    return 0;
}

See if you can fill in the missing code to make this work.

m4ster_r0shi 142 Posting Whiz in Training

If you don't print anything how will you get abdc???

I'll try one last time.

(aa)abbbddccc# print 'a' or don't print?

a(aa)bbbddccc# print 'a' or don't print?

aa(ab)bbddccc# print 'a', print 'b' or don't print?

aaa(bb)bddccc# print 'b' or don't print?

aaab(bb)ddccc# print 'b' or don't print?

aaabb(bd)dccc# print 'b', print 'd' or don't print?

aaabbb(dd)ccc# print 'd' or don't print?

aaabbbd(dc)cc# print 'd', print 'c' or don't print?

aaabbbdd(cc)c# print 'c' or don't print?

aaabbbddc(cc)# print 'c' or don't print?

aaabbbddcc(c#) print 'c', print '#' or don't print?

I want you to give me an answer on every question above.
And remember, I want the final output to be this -> abdc

Narue commented: Some people are lost causes. Props for being optimistic. +17
m4ster_r0shi 142 Posting Whiz in Training

Ok, I'll try to be more specific.

First, you see these two letters -> (aa)abbbddccc#
Then, you see these two -> a(aa)bbbddccc#
Then, you see these two -> aa(ab)bbddccc#
Then, you see -> aaa(bb)bddccc#

etc ...

I want you to tell me what you would do in each
case. Will you print a letter or not? And if you
print a letter, will it be the left or the right one?

Remember, I want the output to be this -> abdc