I'm getting some weird shit here. I'm writing a backup utility for all my stuff and I'm getting 'access denied' to non-system paths when using the System.IO.File.Copy method. I even changed the manifest to [I]requireAdministrator [/I]and it didn't help.
Any ideas?
[editline]17th January 2012[/editline]
One of the paths in question is: C:\Users\.\Desktop\Minecraft\Server
[editline]17th January 2012[/editline]
Haha, that's unfortunate for me, I just realized I'm using File.Copy in an attempt to copy folders. Sorry - nevermind me.
In LOVE is there any way I can open a directory in an explorer window?
[QUOTE=PieClock;34266072]In LOVE is there any way I can open a directory in an explorer window?[/QUOTE]
I'm not too crash hot with love or lua but some quick googling says there's "os.execute". Just do that and call
[code]
os.execute("explorer \"directory name here with spaces\"")
[/code]
Yep, just stumbled upon that myself there now. Works great. Thanks :smile:
Though this is what I'm doing:
[code]os.execute("C:\\windows\\explorer.exe /e, C:\\")[/code]
This is for a problem on an assignment. I'm having trouble sorting three numbers in order of ascension without the use of array, here's what I have in Java so far:
[code]
System.out.println("Enter the first number: ");
int num1= input.nextInt();
System.out.println("Enter the second number: ");
int num2 = input.nextInt();
int minInput = Math.min(num1, num2);
int maxInput = Math.max(num1, num2);
System.out.println("Enter the third number: ");
int num3= input.nextInt();
minInput = Math.min(minInput, num3);
maxInput = Math.max(maxInput, num3);
System.out.println("Numbers in order: " + minInput + " " + maxInput);
[/code]
The problem is that I can't seem to figure out how to get the middle value. Any help appreciated.
[QUOTE=Plastical;34272053]This is for a problem on an assignment. I'm having trouble sorting three numbers in order of ascension without the use of array, here's what I have in Java so far:
[code]
code
[/code]
The problem is that I can't seem to figure out how to get the middle value. Any help appreciated.[/QUOTE]
I'd skip the whole 'min' and 'max' approach and just check for all the combinations using "if a < b and a < c" sort of things.
[editline]18th January 2012[/editline]
Not particularly glamorous, but it works for something of this small scale.
[QUOTE=mechanarchy;34272159]I'd skip the whole 'min' and 'max' approach and just check for all the combinations using "if a < b and a < c" sort of things.
[editline]18th January 2012[/editline]
Not particularly glamorous, but it works for something of this small scale.[/QUOTE]
I did this using 9 if statements. It wasn't beautiful and I had to create a temporary variable, but it worked. Thanks.
[QUOTE=Plastical;34272465]I did this using 9 if statements. It wasn't beautiful and I had to create a temporary variable, but it worked. Thanks.[/QUOTE]
Yeaah... I kinda expected it would look a bit dreadful.
[editline]18th January 2012[/editline]
Just decided to see how it was done. Here's a working python implementation:
[code]
a = int(raw_input("first: "))
b = int(raw_input("second: "))
theMin = min(a, b)
theMax = max(a, b)
c = int(raw_input("third: "))
theMid = 0
if min(c, theMin) == theMin and max(c, theMax) == theMax:
# c is middle
theMid = c
elif min(c, theMin) == theMin:
# c is max
theMid = theMax
theMax = c
else:
# c is min
theMid = theMin
theMin = c
print "minimum value:", theMin
print "middle value:", theMid
print "maximum value:", theMax
[/code]
[editline]18th January 2012[/editline]
It's completely different to what I suggested and far closer to what you had, but oh well. When I started writing it, this was how it turned out compared to what I'd planned.
what would be the best way to integrate Lua into c#?
[QUOTE=kaukassus;34277002]what would be the best way to integrate Lua into c#?[/QUOTE]
[url]http://code.google.com/p/luainterface/[/url]
I need some help with this problem. (C++)
2. Write a program that will prompt the user for a positive integer n, and will use a recursive function to convert n to binary. For example, if n is 19, the output shold be 10011. It should then print the binary number.
[code]
#include <iostream>
using namespace std;
int convertToBinary(int);
int main()
{
int n;
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
while (n != 0)
{
int binary = convertToBinary(n);
cout << "The binary of integer " << n << " is " << binary << ".\n";
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
}
cout << "Bye!\n";
}
int convertToBinary(int n)
{
if (n == 0)
return 0;
return convertToBinary(n/2) + n%2;
}
[/code]
I don't know where to go from here, it's adding the numbers together, and that's not what I want. Any ideas on what I'm doing wrong?
[QUOTE=Leonmyster;34280279]I need some help with this problem. (C++)
2. Write a program that will prompt the user for a positive integer n, and will use a recursive function to convert n to binary. For example, if n is 19, the output shold be 10011. It should then print the binary number.
[code]
#include <iostream>
using namespace std;
int convertToBinary(int);
int main()
{
int n;
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
while (n != 0)
{
int binary = convertToBinary(n);
cout << "The binary of integer " << n << " is " << binary << ".\n";
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
}
cout << "Bye!\n";
}
int convertToBinary(int n)
{
if (n == 0)
return 0;
return convertToBinary(n/2) + n%2;
}
[/code]
I don't know where to go from here, it's adding the numbers together, and that's not what I want. Any ideas on what I'm doing wrong?[/QUOTE]
Well for one thing, you want it to build a string, while instead it's adding integers together.
[QUOTE=Octave;34280737]Well for one thing, you want it to build a string, while instead it's adding integers together.[/QUOTE]
How would I incorporate the string? From what I understand, I can't return it as a string because it's an integer, convertToBinary that is.
My knowledge of strings aren't too good, since my previous professor never taught us string, while this one is all about it.
[QUOTE=Leonmyster;34280810]How would I incorporate the string? From what I understand, I can't return it as a string because it's an integer, convertToBinary that is.
My knowledge of strings aren't too good, since my previous professor never taught us string, while this one is all about it.[/QUOTE]
I'd like to preface this with the fact that my C++ is very limited :v: but for starters, you can change the return type to be a string
[code]string convertToBinary(int n)
{
static string result; // Static so that it will remain between calls of this function rather than being initialized every time
if (n == 0)
return 0;
result.append((n % 2) ? "1" : "0");
return convertToBinary(n/2);
}
[/code]
Haven't tested this yet, but it's a start.
That would just return 0. Maybe try something like:
[code]string convertToBinary( int n )
{
if( n == 0 )
return "0";
return convertToBinary( n / 2 ).append( toString( n % 2 ) );
}[/code]
[editline]18th January 2012[/editline]
No idea how to append to a string in C++ though, maybe with a stream
[del]A lot of the time you want to use stringstreams to convert things into strings.
Read more about 'em [url=http://www.cplusplus.com/reference/iostream/stringstream/]here[/url].
Should explain the concept adequately, seeing as you know how streams work already (cin, cout).[/del]
Maybe I should learn how to read
Okay, fixed some things, this works but the output is reversed, looking for a string reversal function now...
[cpp]string convertToBinary(int n)
{
static string buf;
if (n == 0) return buf;
buf.append((n % 2) ? "1" : "0");
return convertToBinary(n/2);
}[/cpp]
Avoid recursion when it isn't beneficial. If you use it in places where there aren't small upper bounds on the depth of the recursion, you risk a stack overflow. Not to mention the function call overhead.
This would probably be better:
[cpp]string convertToBinary(int n)
{
int bits = 8 * sizeof(int);
int mask = 1 << bits - 1;
string result;
for (int i=0; i < bits; i++) {
result.append(n & mask ? "1" : "0");
mask >>= 1;
}
return result;
}[/cpp]
Instead of reversing the string at the end you could construct it in the opposite order. Also, I'm not sure you can declare static variables inside a method C++, although it has been a while since I last used it.
[QUOTE=Ziks;34281179]Also, I'm not sure you can declare static variables inside a method C++, although it has been a while since I last used it.[/QUOTE]
It's a function, not a method.
[QUOTE=Ziks;34281179]Instead of reversing the string at the end you could construct it in the opposite order. Also, I'm not sure you can declare static variables inside a method C++, although it has been a while since I last used it.[/QUOTE]
I tested it, it does work. But I agree with ROBO_DONUT, this is a silly place to use recursion, although I assume he was doing it for a school assignment and needed to use recursion to do it.
[QUOTE=ROBO_DONUT;34281230]It's a function, not a method.[/QUOTE]
C# dev here, you might be able to understand why I made the mistake
Oh, I didn't read that using recursion is a requirement. Nor did I know this was an assignment. I wouldn't have posted complete code if I knew that were the case.
Well it's not the answer he needs, anyway, so I'll leave it.
[QUOTE=Octave;34281093]Okay, fixed some things, this works but the output is reversed, looking for a string reversal function now...
[cpp]string convertToBinary(int n)
{
static string buf;
if (n == 0) return buf;
buf.append((n % 2) ? "1" : "0");
return convertToBinary(n/2);
}[/cpp][/QUOTE]
Thanks a lot, I'll try to look for the reversal myself.
This is indeed an assignment, and the use of recursion is required here.
[QUOTE=Ziks;34281179]Also, I'm not sure you can declare static variables inside a method C++, although it has been a while since I last used it.[/QUOTE]
Static storage duration. If you define a static variable outside of a function, it has static linking.
So I have my player using a vector2 but when it moves diagonal and but the speed seems to increase only when it goes diagonal... Anyone know how to fix the problem so it stays the same speed always.
sqrt(2)/2
[QUOTE=TH3_L33T;34282085]So I have my player using a vector2 but when it moves diagonal and but the speed seems to increase only when it goes diagonal... Anyone know how to fix the problem so it stays the same speed always.[/QUOTE]
Normalize the vector and then multiply it by a scalar (representing the speed you want it to have).
[QUOTE=ROBO_DONUT;34281169]Avoid recursion when it isn't beneficial. If you use it in places where there aren't small upper bounds on the depth of the recursion, you risk a stack overflow. Not to mention the function call overhead.[/QUOTE]
I find that recursion is often a really nice way of breaking up a problem.
gcc can do tail call optimization anyway, so deliberately avoiding recursion is premature optimization
Just trying to draw a simple ball in Java, but it's not drawing. Here is my Ball class:
[code]import java.awt.geom.*;
import java.awt.*;
import javax.swing.*;
public class Ball extends JPanel{
int width, height;
double ballX, ballY;
Ellipse2D ball = new Ellipse2D.Double(ballX, ballY, width, height);
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.fill(ball);
}
public void setSizes(int w, int h){
width = w;
height = h;
}
public void setCoords(double x, double y){
ballX = x;
ballY = y;
}
}
[/code]
Here is my main class:
[code]import javax.swing.*;
public class Main{
public static void main(String[] args){
JFrame frame = new JFrame("Pong");
Ball ball = new Ball();
frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setLayout(null);
frame.setVisible(true);
frame.add(ball);
ball.setSizes(50, 50);
ball.setCoords(20, 20);
}
}
[/code]
The frame pops up, but the ball doesn't.
Sorry, you need to Log In to post a reply to this thread.