[QUOTE=thf;31859671]I'd read their hint. You should first get the middle value. Then loop through the array and counts the numbers which are less than or equal to it. Then check if that equals the index of the middle element.[/QUOTE]
How would you find the middle value? Modulus? Then it would be a simple if statement for if its greate than array[2], add that to a counter, and then?
[QUOTE=Over-Run;31859713]How would you find the middle value? Modulus? Then it would be a simple if statement for if its greate than array[2], add that to a counter, and then?[/QUOTE]
Middle value should be as simple as finding it's index and then using that. To get the middle index in an array with an odd number of elements just take the number of elements and divide it by two.
Make an if statement like
[code]if (array[i] < array[middle])
{
elementsLowerThanMiddle++;
}[/code]
This is assuming there are no duplicate numbers in the arrays like you said.
Then check elementsLowerThanMiddle against middle. If the middle element's index is the same number as the count of elements lower than it, it's at the right position :v:
[QUOTE=thf;31860287]Middle value should be as simple as finding it's index and then using that. To get the middle index in an array with an odd number of elements just take the number of elements and divide it by two.
Make an if statement like
[code]if (array[i] < array[middle])
{
elementsLowerThanMiddle++;
}[/code]
This is assuming there are no duplicate numbers in the arrays like you said.
Then check elementsLowerThanMiddle against middle. If the middle element's index is the same number as the count of elements lower than it, it's at the right position :v:[/QUOTE]
Jesus christ you make it seem so easy ha ha. I don't know I just forgot everything about programming over Summer and haven't touched it since college finished ha. Thanks once again pal!
[QUOTE=Over-Run;31860373]Jesus christ you make it seem so easy ha ha. I don't know I just forgot everything about programming over Summer and haven't touched it since college finished ha. Thanks once again pal![/QUOTE]
It's not hard at all. Just think logically and you'll find the solution to most problems.
[QUOTE=thf;31860572]It's not hard at all. Just think logically and you'll find the solution to most problems.[/QUOTE]
Yeah my problem is logical thinking haha I always mess something up!
Hey guys, Im learning Visual C# and I'm having trouble with a calculator. Heres the code block that relates to Plus, Minus and Equals:
[code] private void SymPlus_Click(object sender, EventArgs e)
{
Sum1 += double.Parse(MainDisplay.Text);
MainDisplay.Clear();
textBox1.Text = Sum1 + " + ";
bool SymPlusClicked = true;
bool SymMinusClicked = false;
}
private void SymMinus_Click(object sender, EventArgs e)
{
Sum1 -= double.Parse(MainDisplay.Text);
MainDisplay.Clear();
textBox1.Text = Sum1 + " - ";
bool SymPlusClicked = false;
bool SymMinusClicked = true;
}
private void SymEq_Click(object sender, EventArgs e)
{
if (SymPlusClicked == true)
{
Sum2 = Sum1 + double.Parse(MainDisplay.Text);
MainDisplay.Text = Sum2.ToString();
Sum1 = 0;
textBox1.Text = "Answer:";
}
else if (SymMinusClicked == true)
{
Sum2 = Sum1 - double.Parse(MainDisplay.Text);
MainDisplay.Text = Sum2.ToString();
Sum1 = 0;
textBox1.Text = "Answer:";
}
}[/code]
I get the error 'The name 'SymPlusClicked' does not exist in the current context', same for minus. I can't figure out whats wrong. I'm expecting it to be something so basic.
So my Asteroids clone is coming along alright, but for some reason my ship is queuing up lasers to fire and only firing them once the last laser has been removed from the ArrayList I've set up.
[code]public static void updateInGame(GameContainer container)
{
processInputInGame(container.getInput());
EntityManager.currentPlayer.updatePosition();
if (!EntityManager.lasers.isEmpty())
{
Iterator<Laser> iter = EntityManager.lasers.iterator();
Laser l = iter.next();
l.updatePosition();
if (l.offScreen())
iter.remove();
}
}[/code]
[QUOTE=Chris220;31858986]No problem :P
I've been poking around a bit, the error itself is:
[code]Windows has triggered a breakpoint in ld21.exe.
This may be due to a corruption of the heap, which indicates a bug in ld21.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while ld21.exe has focus.
The output window may have more diagnostic information.[/code]
The output window says:
[code]HEAP[ld21.exe]: HEAP: Free Heap block 612e228 modified at 612e260 after it was freed[/code]
How can I go about finding what modified that block after it was freed?[/QUOTE]
Overload the operators new and delete. You can find some stuff about that on the internet.
[QUOTE=thf;31860572]It's not hard at all. Just think logically and you'll find the solution to most problems.[/QUOTE]
Just tried to do the question and I am still having some trouble with it.
[code] int array [] = {2,7,4,8,1};
int x = array.length;
int middle = (x / 2) + 1;
int middlenum [] = {middle};
for(int i = 0;i < array.length;i++){
if(array[i]< middlenum)
} [/code]
[QUOTE=Over-Run;31863691]Just tried to do the question and I am still having some trouble with it.
[code] int array [] = {2,7,4,8,1};
int x = array.length;
int middle = (x / 2) + 1;
int middlenum [] = {middle};
for(int i = 0;i < array.length;i++){
if(array[i]< middlenum)
} [/code][/QUOTE]
Middle should be just (x / 2), not + 1.
I'd do it like this
[code]int[] array = {2, 7, 4, 8, 1}
int middle = (array.length / 2);
int numBiggerThanMiddle = 0;
for (int i = 0; i < array.length; i++)
{
if (array[i] < array[middle])
{
numBiggerThanMiddle++;
}
}
[/code]
Then if numBiggerThanMiddle == middle, it's at the right position.
[QUOTE=FlamingSpaz;31862128]I get the error 'The name 'SymPlusClicked' does not exist in the current context', same for minus. I can't figure out whats wrong. I'm expecting it to be something so basic.[/QUOTE]
You've declared SymPlusClicked and SymMinusClicked as local variables inside your SymPlus_Click()/SymMinus_Click() functions, so you can't use them inside SymEq_Click(). You have to declare them as members of the class that contains your functions if you want to use them like that. And don't forget to change 'bool SymPlusClicked = false' to 'SymPlusClicked = false' etc. after you do it, or you end up modifying the wrong variables (local ones instead of members).
[QUOTE=thf;31863741]Middle should be just (x / 2), not + 1.
I'd do it like this
Then if numBiggerThanMiddle == middle, it's at the right position.[/QUOTE]
Man your such a beast ha I got it working now, I'll just paste the full code and make sure that it looks good to you, let me know if theres anything I should improve on. Also I just added in the boolean bit because I forgot that the question asks for it to take a parameter of an array and return a boolean value. Thanks man
[code]public class apples {
public static boolean middlePosition(int [] a){
boolean isSame = false;
int middle = a.length / 2;
int numBiggerThanMiddle = 0;
for(int i = 0; i < a.length; i++){
if(a[i] < a[middle])
numBiggerThanMiddle++;
}
if(numBiggerThanMiddle == middle)
return true;
return isSame;
}
public static void main (String [] args){
int array [] ={11,18,36,14,12};
System.out.println(middlePosition(array));
}
}[/code]
[QUOTE=ZeekyHBomb;31862673]Overload the operators new and delete. You can find some stuff about that on the internet.[/QUOTE]
Thanks, I'll have a play with those and see what I can come up with.
[QUOTE=Over-Run;31863947]Man your such a beast ha I got it working now, I'll just paste the full code and make sure that it looks good to you, let me know if theres anything I should improve on. Also I just added in the boolean bit because I forgot that the question asks for it to take a parameter of an array and return a boolean value. Thanks man
[code]public class apples {
public static boolean middlePosition(int [] a){
boolean isSame = false;
int middle = a.length / 2;
int numBiggerThanMiddle = 0;
for(int i = 0; i < a.length; i++){
if(a[i] < a[middle])
numBiggerThanMiddle++;
}
if(numBiggerThanMiddle == middle)
return true;
return isSame;
}
public static void main (String [] args){
int array [] ={11,18,36,14,12};
System.out.println(middlePosition(array));
}
}[/code][/QUOTE]
That isSame variable seems pretty unnecessary...
[code]public class apples {
public static boolean middlePosition(int [] a){
int middle = a.length / 2;
int numBiggerThanMiddle = 0;
for(int i = 0; i < a.length; i++){
if(a[i] < a[middle])
numBiggerThanMiddle++;
}
if(numBiggerThanMiddle == middle)
return true;
else
return false;
}
public static void main (String [] args){
int array [] ={11,18,36,14,12};
System.out.println(middlePosition(array));
}
}[/code]
[QUOTE=thf;31864032]That isSame variable seems pretty unnecessary...
[/QUOTE]
Ahh good point actually. Fixed that up now. Cheers man. I sort of have the next part working, which asks you to print every element that is in the correct order, by that I presume they mean like i < i+1. II'm just testing it with a "correct" and "incorrect" statement at the moment, , and it correctly identifies if they are right or wrong, but I get an out of bounds error at the end of it :S
[code] public static void correctOrder(int [] a){
for(int i = 0; i < a.length + 1; i++){
if(a[i] < a[i+1])
System.out.println("Is correct");
else
System.out.println("Is not correct");
}
}[/code]
I think it must be an issue with the last index in the array not being correctly read or something.
[QUOTE=Over-Run;31864199]Ahh good point actually. Fixed that up now. Cheers man. I sort of have the next part working, which asks you to print every element that is in the correct order, by that I presume they mean like i < i+1. II'm just testing it with a "correct" and "incorrect" statement at the moment, , and it correctly identifies if they are right or wrong, but I get an out of bounds error at the end of it :S
[code] public static void correctOrder(int [] a){
for(int i = 0; i < a.length + 1; i++){
if(a[i] < a[i+1])
System.out.println("Is correct");
else
System.out.println("Is not correct");
}
}[/code]
I think it must be an issue with the last index in the array not being correctly read or something.[/QUOTE]
You can't really mean that [b]one[/b] element is in the right order, are you they don't mean in the right position?
[QUOTE=thf;31865382]You can't really mean that [b]one[/b] element is in the right order, are you they don't mean in the right position?[/QUOTE]
My mistake, the question said correctly positioned. I'm just assuming its a comparison between a sorted version of the array and the non sorted.
What am I doing wrong for camera control here?
[csharp]
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// I TOLD YOU ABOUT THAT KEY DETECTION. I TOLD YOU DOG.
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.D))
angleSide += 0.05f;
if (keyState.IsKeyDown(Keys.A))
angleSide -= 0.05f;
if (keyState.IsKeyDown(Keys.W))
angleUpDown += 0.05f;
if (keyState.IsKeyDown(Keys.S))
angleUpDown -= 0.05f;
if (keyState.IsKeyDown(Keys.I))
directionForwardBack += 1f;
if (keyState.IsKeyDown(Keys.K))
directionForwardBack += 1f;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
Matrix viewMatrix = Matrix.CreateRotationY(angleSide) * Matrix.CreateRotationX(angleUpDown) * Matrix.CreateTranslation(0, 0, directionForwardBack);
}
[/csharp]
The camera just kinda flips the fuck out when I try to rotate it up and down when I've moved it forward.
Why aren't you putting your viewMatrix update in the Update() loop?
You should only have draw calls in the Draw() loop
[QUOTE=CarlBooth;31866168]Why aren't you putting your viewMatrix update in the Update() loop?
You should only have draw calls in the Draw() loop[/QUOTE]
Thanks for the tip, but the problem with the camera flipping out more the further it moves is still there. I'm REALLY new to XNA, and I don't 100% know what I'm doing here.
Anyone got any resources for how to quickly get the point of collision when using the separating axis theorem? My current method is to try and find the closest point to the edge that gave the minimum translation vector but it's very unreliable on large edges and edge/edge collision cases.
Probably a stupid question, but I need to add preprocessor definitions, and everything I read keeps telling the breadcrumbs are "Project->Properties->C/C++->Preprocessor", however I'm not seeing a C/C++ category anywhere, and looking through all the menus, I have yet to see anywhere to paste in the preprocessor shit.
I thought this was a version thing but I just read one that claimed to be for 2010...
Got the camera working.
[QUOTE=RyanDv3;31868293]Probably a stupid question, but I need to add preprocessor definitions, and everything I read keeps telling the breadcrumbs are "Project->Properties->C/C++->Preprocessor", however I'm not seeing a C/C++ category anywhere, and looking through all the menus, I have yet to see anywhere to paste in the preprocessor shit.[/QUOTE]
[img]http://dl.dropbox.com/u/11093974/Junk/preprocessor.png[/img]
You can add in more definitions there. Things like "NDEBUG=5" will also work.
I just figured out that C/C++ doesn't show up till you add a .cpp file.
It was some random tip in the wiki for qt. My project has nothing to do with qt. Jesus Christ.
Sometimes being a programmer feels like playing the lottery
[QUOTE=Mr. Smartass;31868322]Got the camera working.[/QUOTE]
Glad to hear. Make sure to not tell anyone how you did it, just in case someone Googles the problem.
[QUOTE=Hypershadsy;31870520]Glad to hear. Make sure to not tell anyone how you did it, just in case someone Googles the problem.[/QUOTE]
Sorry. I followed [url=http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Mouse_camera.php]this[/url] tutorial.
Beaten down Jookia here.
I thought using cross platform libraries like Boost, ICU and SDL would mean my application would be portable to Windows. I was wrong.
Is there some magic button that allows me to install Boost and ICU on Windows?
What ever happened to this project?
[img]http://dl.dropbox.com/u/3724424/Programming/bug3.gif[/img]
I'm not sure if this is the right place to post this, but..
My friend and I are developing an iPhone application. We want to be able to post the user's high score on facebook (very much like doodle jump). How would this be done?
Sorry, you need to Log In to post a reply to this thread.