sfuo 111

You can use System.IO.Directory.GetFiles(DIRECTORY_NAME); which will return an array of strings that contain all the files (with full path) in that folder.

PulsarScript commented: Thank you +2
sfuo 111

I know this is a bit late and you may have come up with a solution already but here is a method you could use.

pbGameBox is a PictureBox object from the C# Toolbox.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace dani_mapEditor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        void onTick(object sender, EventArgs e)
        {
            Point P = PointToScreen(new Point(pbGameBox.Bounds.Left, pbGameBox.Bounds.Top));
            Int32 X = Cursor.Position.X - P.X;
            Int32 Y = Cursor.Position.Y - P.Y;

            if (X < 0 || Y < 0 || X > pbGameBox.Bounds.Width || Y > pbGameBox.Bounds.Height)
                this.Text = "--, --";
            else
                this.Text = String.Format("{0}, {1}", X, Y);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Timer aTimer = new Timer();
            aTimer.Interval = 10;
            aTimer.Tick += new EventHandler(onTick);
            aTimer.Enabled = true;

            GC.KeepAlive(aTimer);

        }
    }
}

All this does is updates the title of the window (with the use of a timer) to the X, Y coordinates of the mouse within the PictureBox. If the mouse is out of bounds of the PictureBox then it just displays "--, --".

sfuo 111

I am not a Unix/Linux user so I am not 100% sure but after reading on GetOpt here and a GetOpt example here I would say the short answer is you must write myprogram.c -t file1 file2 file3 because it parses for options first.

sfuo 111

Line 18 of what you posted makes no sense. It will always select maximum = maximum in the trinary operator and you cannot declare a variable equal to an undeclared variable (even if you could it would be holding a garbage value).

Line 19 you are now saying that the low guess is equal to some mystery value and your high guess is the maximum tolerated error? and then your maxError is now set to 0 and never used within your helper function.

In your helper function the only two lines that make sense are the first two where you calculate the average and the resulting fifth power of that value. Other than that I do not fully understand what you are trying to do because fifthPower - x will not give anything useful the way you are using it (maybe if you used maxError in here somewhere then it would make sense, but then again you are setting that to 0.0).

Here is what I think you are attempting to do

#include <iostream>
#include <cmath>

using namespace std;

double fifthRootHelper(double x, double maxError, double low, double high)
{
    if (x == 1.0) //special case for 1.0
        return 1.0;

    double avg = (low + high) / 2.0;  //use 2.0 not 2 just for the future case of running into integer division without knowing
    double fifthPower = avg*avg*avg*avg*avg;

    if (fabs(fifthPower - x) < maxError) //if our new guess is within our error, return that as the answer
        return avg;

    if (fifthPower ...
sfuo 111

I would suggest that you do not try to store all your information in labels, but rather have seperate variables that control the amount of each stat that your character has and then display those values in the labels.

I tossed together a quick example of how you can use buttons to increase and decrease the stats for your character. I am sure there are better ways of coding this but this should get you on track and going.

UI is here - http://i.imgur.com/zS0hM22.png

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DaniRPG
{
    public partial class Form1 : Form
    {
        Player me;
        Int32 remainingPoints;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            me = new Player();
            remainingPoints = 20;

            lblAgiPts.Text = me.Agility.ToString();
            lblIntPts.Text = me.Intelligence.ToString();
            lblStrPts.Text = me.Strength.ToString();
            lblStamPts.Text = me.Stamina.ToString();
            lblRemainingPts.Text = remainingPoints.ToString();
        }

        private void btnStrInc_Click(object sender, EventArgs e)
        {
            if (remainingPoints > 0)
            {
                me.Strength++;
                remainingPoints--;
                lblStrPts.Text = me.Strength.ToString();
                lblRemainingPts.Text = remainingPoints.ToString();
            }
        }

        private void btnStrDec_Click(object sender, EventArgs e)
        {
            if (me.Strength > 0)
            {
                me.Strength--;
                remainingPoints++;
                lblStrPts.Text = me.Strength.ToString();
                lblRemainingPts.Text = remainingPoints.ToString();
            }
        }

        private void btnAgiInc_Click(object sender, EventArgs e)
        {
            if (remainingPoints > 0)
            {
                me.Agility++;
                remainingPoints--;
                lblAgiPts.Text = me.Agility.ToString();
                lblRemainingPts.Text = remainingPoints.ToString();
            }
        }

        private void btnAgiDec_Click(object sender, EventArgs e)
        {
            if (me.Agility > 0)
            {
                me.Agility--;
                remainingPoints++;
                lblAgiPts.Text = me.Agility.ToString();
                lblRemainingPts.Text = remainingPoints.ToString();
            }
        }

        private void btnIntInc_Click(object sender, EventArgs e)
        {
            if (remainingPoints > 0) ...
sfuo 111

Just a question.
Could you tell me how you thought this:

a[maxIndex] = a[r*N + r];

I mean the index r*N + r.
As I can see it gives the diagonal elements.
I didn't know about that!

The diagonal elements occur when the row index is equal to the column index. We use "r" in this case because we are iterating through the rows with the outer most for loop. If you write the matrix out on paper and try to come up with general solutions using only constants (N in this case) and variables that you are controling (r and c), you can come up with equations that you can input directly into your code.

Also, do you have a solution using the max value instead of the max index?

Because ,I can't figure why I couldn't get the proper max value.

You could use the max value but you will have to keep track of the column index of the max value (unless you want to scan through the columns after finding the max value to find it again and do the swap, which I think is a bad idea).

for (int r = 0; r < N; r++)
{
    //"Assume" maxValue is the first element of the row
    double maxValue = fabs(a[r*N]);
    int col = 0;

    //Check to see if the rest of the elements are greater than current max value
    for (int c = 1; ...
sfuo 111

Not sure why you are switching values in the b array or why your swap function uses loops.

#include <iostream>
using namespace std;

int main()
{
    const int N = 3;
    double *a = new double[N*N];
    double *b = new double[N];
    double *x = new double[N];

    a[0] = 9;
    a[1] = 3;
    a[2] = 1;
    a[3] = 0;
    a[4] = 4;
    a[5] = 5;
    a[6] = 8;
    a[7] = 1;
    a[8] = 4;

    b[0] = 7;
    b[1] = 8;
    b[2] = 9;

    cout << "Before" << endl;
    for (int r = 0; r < N; r++)
    {
        for (int c = 0; c < N; c++)
            cout << a[r*N + c] << " ";
        cout << b[r] << endl;
    }

    cout << endl;

    for (int r = 0; r < N; r++)
    {
        //"Assume" maxIndex is the first element of the row
        int maxIndex = r*N;

        //Check to see if the rest of the elements are greater than current max index
        for (int c = 1; c < N; c++)
        {
            //If it is greater then set the max index to the current index
            if (fabs(a[r*N + c]) > fabs(a[maxIndex]))
                maxIndex = r*N + c;
        }

        cout << "Max = " << fabs(a[maxIndex]) << " idx = " << maxIndex - r*N << endl;

        //If the max index is not a diag then lets switch it
        if (maxIndex - r*N != r) //col != row aka diag
        {
            double tmp = a[maxIndex];
            a[maxIndex] = a[r*N + r];
            a[r*N + r] ...
sfuo 111

Do you mean the constructor?

You make a public function within the class that has no return (not void) and also has the same name as the class.

#include <iostream>
using namespace std;

class Square
{
    int _side;

public:

    Square(){};

    Square(int side)
    {
        _side = side;
    }
};

int main()
{
    Square aSquare;
    Square bSquare(10);

    return 0;
}
sfuo 111

Line 17 should be display->array = (char **) malloc(sizeof(char*) * height);
Note that it is sizeof(char*) not sizeof(char) because you are trying to allocate char pointers which have a size of 4, where a char has a size of 1.

Also your display function will not work as intended because you did not null-terminate your char arrays ('\0'). You can either null-terminate them or print the arrays out char by char, opposed to trying to print each line using the c-string format option in printf.

sfuo 111

If your function is always going to be composed of A*x^0 + B*x^1 + ... N*x^n then why don't you integrate the function analytically and then evaluate it at the bounds x1 and x2 and subtract them.
example:
f(x) = 10x - 5x^2
x1 = 1, x2 = 5
int(f(x)) = (10/2)x^2 - (5/3)x^3 + C
int(f(5)) - int(f(1)) = Area under curve
((10/2)*5^2 - (5/3)*5^3 + C) - ((10/2)*1^2 - (5/3)*1^3 + C) = Area under curve
Note C-C = 0 so we do not need to solve for C

This method will give you the exact answer rather than a numerical approximation found using rectangle/triangle/simpsons methods.

Coding power rule integration is really easy because it follows an easy form, with the exception of int(x^-1) which is ln(x) + C.
Note ln(x) in C/C++ is log(x) and log(x) is log10(x)

The form is:
f(x) = A*x^n
int(f(x)) = (A/(n+1))*x^(n+1) + C

Because you are always going to be evaluating between two bounds, you can ignore the whole + C part of the integration in your code.

Using this analytical method in your code will not require many changes other than adding a function that will integrate the function input by the user. You can also use a similar function to findHeightOfFunction() that just evaluates the integrated function at a specific point.

As for your findHeightOfFunction() function, you are on the right track with the whole loop idea and the line of code you have that multiplies the coeff with ...

sfuo 111

int compare (const void * a, const void * b)
The two values 'a' and 'b' are of type void pointer and we want this function to compare two integers so we must convert from void pointers to integers.

To do this we first cast the void pointer into an integer pointer.
(int*)a This leaves us with a pointer to an integer

Next we want to get the value in which the integer pointer is looking at by dereferencing the pointer with '*'.

*(int*)a This will convert the void pointer into an integer pointer, then dereference the integer pointer and leave us with an integer.

You could break this up in such a way that it is very clear to see what is going on but basically all that is happening here is a cast and a dereference all done on one line.

sfuo 111

You would have to use a custom data type. A double can only hold so much precision.

sfuo 111

If you want to make a console application (the black cmd window) you select the Win32 Console Application project type. If you do not want the console to show then you create a Win32 Project, if you are using SDL or GLUT then you can call some of their library functions to create a window and then you just pass in functions into a callback that they specify (if you follow a tutorial you will figure out what I'm talking about). If you do not use SDL or GLUT (or similar library bundles) then you will have to look into WinAPI and it is not fun because it is written in C and has all of Window's custom data types and functions.

I'm going to assume that you are starting with SDL. If you read Lazy Foo's first tutorial and select Window > Visual Studio 2010, he gives you a step by step of what you need to do to get started.

sfuo 111

Since you have just recently started learning C++ and I don't know what programming background you have. I would suggest that you learn the foundations of the language before moving on to graphics.

While you are learning the lanuage you should think of really basic "games" that you could complete in a console window (i.e. tic-tac-toe, blackjack, and other easy card games). These games will help you by making you use a many parts of the C++ language all together.

After you feel more comfortable with the language then you should really think about what IDE and graphics library you want to use. Alternativly you can use a game engine that will handle graphics, physics, sound, GUIs, and much more, but this depends on if you actually want to learn how to program or just make games that are bound by their engine. Personally I like to try to make my own "libraries" with the exception of a graphics library because that would be just crazy.

I use OpenGL and VS2012, however if you are just starting out I would suggest using SDL or another "simplified" graphics library. This way you are not spending lots of time learning the graphics library and instead you can focus on learning how to use the language and understand how a game works.

Here is the C++ tutorial website that I used to learn the language and I still use this website as a reference for the standard libraries.

Here is a link to ...

sfuo 111

Do you not have a main() function in your program? If what you posted is your program and not just a snippet then you need to throw in main().

sfuo 111

If you are new to game programming then you should start with a 2D game. There is a massive gap between 2D and 3D if you plan on writing any of your own code (physics or other engine elements).

sfuo 111

strcpy() works with c-strings and those are arrays of characters that have a '\0' terminating character. You are using a C++ string and they have the '=' operator overloaded so you just have to write string1 = string2; and that will copy the contents of string2 into string1.

I would not use strcpy() and I wouldn't make a new string variable 'x'. It looks like you could just write cin >> temp->TeamName; and that would work the way you want it.

sfuo 111

If you have the function prototypes within the class and you want to define them outside, you need to define them with the proper scope.

Right now you are just declaring some functions in the global scope. To define the class's functions you need to include the scope of the class in the function definition.

For example:

void BitPattern::ReadBitPattern (ifstream& infile)
{
    char ch;

    if(ch == '0')
    {
        for (int index = 0; index < PatternSize; index++) 
        {
            cin.get (ch);
        }
    }

    else 
    {
        for (int index = 0; index < PatternSize; index++)
        {

        }
    }
}

Notice how BitPattern:: is before the function name?

sfuo 111

why do you have the return 0; line out of main()?

sfuo 111

You will also find that your setDriver() and setOwner() functions will cause a crash. To fix this you can do the following.

//called in main()
carPtr->setDriver(people[personNum]);
carPtr->setOwner(people[personNum]);

//in Car class
void setDriver(Person *d)
{
    driver = d;
}
void setOwner(Person *o)
{
    owner = o;
}
sfuo 111

Well line 86 is going to have the same problem.

sfuo 111

You obviously didn't read the other thread that you started. I posted code that would output what that is and I said it is not a word or words it is just junk.

sfuo 111

If you don't want to use the table you can just use a program to print out what the char for those hex values would be.

#include <iostream>
using namespace std;

int main()
{
    char message[] = { 0x4B, 0x50, 0x7B, 0xF1, 0xF4, 0xF5, 0x5E, 0x50, 0x7B, 0xF1, 0xF4, 0xF5, 0x5E, 0x4B, 0x4B, 0x4B };

    for( int i = 0; i < 16; i++ )
        cout << message[i];
    cout << endl;

    cin.get();
    return 0;
}

The message is junk but maybe you can make something out of it. I'll let you run it and see what it is.

sfuo 111

We are asking you to post code. We will not help you unless you show that you have done some work.

sfuo 111

So if you were to go based off my previous post you would pick option #3.

This would be pretty much instant because all the minimum number locations and values have already been saved into an array.

Another approach to this would be to do as deceptikon and pyTony suggested, which is sorting the list and then iterating to the kth element of the sorted list. This would take a bit longer since you have to sort a list that could be very large. However I haven't actually bothered with sorting large containers so I wouldn't know if it would be that big of an issue.

sfuo 111

How about you post up some code and then show us exactly where you are having problems. Writing out a big mal-formed paragraph isnt going to make us help you.

sfuo 111

At any point of time, I am asked to return the kth(it is given initally) minimum element from the elements read so far.

When I read this I can interperet it three different ways:
1) You are at the 'kth' element and you want to know what the minimum element so far is
2) You are at the 'kth' element and you want to know what the minimum element at any point before the 'kth' point is
3) You are at the 'kth' element and you want to know what the 'nth' minimum element is (eg numbers are 10, 9, 11, 14, 15, 8 -- 3rd minimum element would be 8)

The first option would be very easy since you would just read in and check if the current minimum is less than the read in value, if not then the read in value is the new minimum.

The second option would require you to keep a history of some sort which tells you where the minimum changed and what it became, then you would have to find the point that is less than or equal to the 'kth' element.

The third option would be like the second option but instead of checking where it changed you just access the history array (or other container) at the 'kth' index.

When asking questions you have to be clear as to what is going on.

sfuo 111

If you were to throw return user; at the bottom of your function the error would go away. This is because if for some reason it did not go into your using statements it would never see a return statement.

sfuo 111

Or instead of using an int array you could use a map (or unordered_map if you have a compiler that supports C++11).

Accessing the values would be exactly the same but instead of having an array with a size of 97 + 26 (because 'a' is 97 (as said above) and then you need room up until 'z') you would have a map with 26 entries. Obviously maps have overhead that a normal array does not, but I think it would be good to play around with some of the STL containers so that you know how to use them and what each of them can and cannot do.

#include <iostream>
#include <map>

using namespace std;

int main()
{
    map<char, int> myMap;

    for( int i = 0; i < 26; i++ )
        myMap['a'+i] = i;

    cout << myMap['c'] << endl;

    cin.get();
}

By the way (I'm sure you just wrote it out and didn't actually test it) you defined an int array of size 10 but assigned/accessed out of bounds (in your second example).

DeanMSands3 commented: While NathanOliver and AncientDragon give "correct" answers, this is probably the most useful. +5
sfuo 111

All three errors are from line 23 in your original post. If you read my post then you should have been able to correct that line and you would not have any more errors.