• What Do You Need Help With? V6
    7,544 replies, posted
Would this be the correct way of using a unique_ptr in conjunction with move? [cpp]player.addStudent(std::unique_ptr<Student>(new Student(200+300*i, WINDOW_HEIGHT-160))); void Player::addStudent(std::unique_ptr<Student> && stud){ students.push_back(std::move(stud)); }[/cpp]
I've always taken the parameter by value, but this should work fine, too. [editline]26th October 2013[/editline] [url=http://stackoverflow.com/questions/8114276/how-do-i-pass-a-unique-ptr-argument-to-a-constructor-or-a-function/8114913#8114913]By value[/url] seems better.
Hey guys, trying to multiply these two strings together to get each possibility of for each letter. So the end result looks like, "AA, AB, AC, AD, ..." [CODE]public class Letters { public static void main(String[] args) { String[] lettersOdds = { "A", "C", "E", "G", "I", "K", "M", "O", "Q", "S", "U", "W", "Y" }; String[] lettersEvens = { "B", "D", "F", "H", "J", "L", "N", "P","R","T","V","X", "Z" }; String[][] theAlphabet = {lettersOdds, lettersEvens}; for (int i = 0; i <theAlphabet.length; i++) { for(int j = 0; j <theAlphabet[i].length; j++) { System.out.println(theAlphabet[i][j] + i*j); } } } }[/CODE] How did I mess up so badly?
Your solution seems weird, and I would like to explain why it doesn't work by after attempting to I decided it would only confuse you more. Instead, have a look at my solution: [cpp]public class Letters { public static void main(String[] args) { String[] lettersOdds = { "A", "C", "E", "G", "I", "K", "M", "O", "Q", "S", "U", "W", "Y" }; String[] lettersEvens = { "B", "D", "F", "H", "J", "L", "N", "P","R","T","V","X", "Z" }; for (int i = 0; i <lettersOdds.length; i++) { for(int j = 0; j <lettersEvens.length; j++) { System.out.println(lettersOdds[i] + lettersEvens[j] + ", "); } } } }[/cpp] [editline]26th October 2013[/editline] Wait, I have an issue with your problem. You want each combination of letters between the different strings right? But you would never get the combination AA or AC. I think I'm misunderstanding the question.
[QUOTE=WTF Nuke;42652284]Your solution seems weird, and I would like to explain why it doesn't work by after attempting to I decided it would only confuse you more. Instead, have a look at my solution: [cpp]public class Letters { public static void main(String[] args) { String[] lettersOdds = { "A", "C", "E", "G", "I", "K", "M", "O", "Q", "S", "U", "W", "Y" }; String[] lettersEvens = { "B", "D", "F", "H", "J", "L", "N", "P","R","T","V","X", "Z" }; for (int i = 0; i <lettersOdds.length; i++) { for(int j = 0; j <lettersEvens.length; j++) { System.out.println(lettersOdds[i] + lettersEvens[j] + ", "); } } } }[/cpp] [editline]26th October 2013[/editline] Wait, I have an issue with your problem. You want each combination of letters between the different strings right?[B] But you would never get the combination AA or AC. [/B]I think I'm misunderstanding the question.[/QUOTE] That's my question. Do I create another another String [] lettersAllAlphabet {"A", "B", "C", ... "X", "Y", "Z"}, and add it to the multiplication?
[QUOTE=blacksam;42652332]That's my question. Do I create another another String [] lettersAllAlphabet {"A", "B", "C", ... "X", "Y", "Z"}, and add it to the multiplication?[/QUOTE] [cpp]String[] lettersAllAlphabet = new String[lettersOdds.length + lettersEvens.length]; System.arraycopy(lettersOdds, 0, lettersAllAlphabet, 0, lettersOdds.length); System.arraycopy(lettersEvens, 0,lettersAllAlphabet, lettersOdds.length, lettersEvens.length);[/cpp] That would get you an array of strings with all the letters, then you could do what I did but with each string added against this one.
[QUOTE=blacksam;42652211]Hey guys, trying to multiply these two strings together to get each possibility of for each letter. So the end result looks like, "AA, AB, AC, AD, ..." [CODE]public class Letters { public static void main(String[] args) { String[] lettersOdds = { "A", "C", "E", "G", "I", "K", "M", "O", "Q", "S", "U", "W", "Y" }; String[] lettersEvens = { "B", "D", "F", "H", "J", "L", "N", "P","R","T","V","X", "Z" }; String[][] theAlphabet = {lettersOdds, lettersEvens}; for (int i = 0; i <theAlphabet.length; i++) { for(int j = 0; j <theAlphabet[i].length; j++) { System.out.println(theAlphabet[i][j] + i*j); } } } }[/CODE] How did I mess up so badly?[/QUOTE] This is what you want [cpp]public class Letters { public static void main(String[] args) { String[] letters = { "A","B", "C","D", "E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; for (int i = 0; i <letters.length; i++) { for(int j = 0; j <letters.length; j++) { System.out.println(letters[i] + letters[j] + i*j); } } } }[/cpp]
Hey guys, another question. What would you recommend for an "if/else" type situation with 3 different outcomes? Here's my code: [code] // Movie.cpp Ticket Pricing, anyone over 65 = $5.00, under 12 is $7.00, // anyone between those two is $8.00 // Aaron White #include <iostream> #include <iomanip> #include <string> #include <fstream> #include "StdAfx.h" using namespace std; int _tmain() { //declare variables int age; string name; //get user input cout << "Greetings. What is your name? "; cin >> name; cout << "Excellent. " << name << ", how old are you? " ; cin >> age; //use varibables to determine age. if( age >= 65 ) { cout << "Your ticket wil be $5.00. ";} else { cout << } [/code] I know the code's incomplete, but i figured i would get some ideas. We have 3 types of different scenarios for this. We're setting "ticket prices" based on age. So if you're older than 85, it's one price. Below 12, another, and between the two it's a 3rd price. I'm thinking if i set the if(age>=65) then print the "ticket is blah blah" but then i'm not sure how to handle the next part. Can you have multiple "else" statements? If it were two ages, it would be easier, but since there's three it's throwing me for a bit of a loop.
Hey, I know this has probably been asked a few times but, I couldn't find my answer. I'm actually doing some 3D in xna and I can't get the collision resolution right. How do you guys normally do your collisions? I have a BoundingBox for the player and an other one for the object it collides. I've tried many things but I can't get it right.
[QUOTE=JohnStamosFan;42654372]Hey guys, another question. What would you recommend for an "if/else" type situation with 3 different outcomes? Here's my code: [code] // Movie.cpp Ticket Pricing, anyone over 65 = $5.00, under 12 is $7.00, // anyone between those two is $8.00 // Aaron White #include <iostream> #include <iomanip> #include <string> #include <fstream> #include "StdAfx.h" using namespace std; int _tmain() { //declare variables int age; string name; //get user input cout << "Greetings. What is your name? "; cin >> name; cout << "Excellent. " << name << ", how old are you? " ; cin >> age; //use varibables to determine age. if( age >= 65 ) { cout << "Your ticket wil be $5.00. ";} else { cout << } [/code] I know the code's incomplete, but i figured i would get some ideas. We have 3 types of different scenarios for this. We're setting "ticket prices" based on age. So if you're older than 85, it's one price. Below 12, another, and between the two it's a 3rd price. I'm thinking if i set the if(age>=65) then print the "ticket is blah blah" but then i'm not sure how to handle the next part. Can you have multiple "else" statements? If it were two ages, it would be easier, but since there's three it's throwing me for a bit of a loop.[/QUOTE] [code] if(first condition) { first result } else if(first alternative condition) { second result } else if(second alternative condition) { third result } else { //everything not caught by the previous conditions triggers this other result } [/code]
[QUOTE=JohnStamosFan;42654372]Hey guys, another question. What would you recommend for an "if/else" type situation with 3 different outcomes? [...][/QUOTE] You can write any statement of block instead of the {} blocks in a if {} else {}, so you can write [code]if([...]) { [...] } else if([...]) { [...] } else { [...] }[/code] This is basically the same as [code]if([...]) { [...] } else { if([...]) { [...] } else { [...] } }[/code], just with a bit nicer formatting. (Most formatters shouldn't deepen the indentation across the "else if" line.) Please don't skip the {} on random statements though, it makes code hard to read. An if, return, continue or goto [U]on the same line[/U] are where I usually make an exception but otherwise alsmost never.
[QUOTE=mobrockers;42654629][code] if(first condition) { first result } else if(first alternative condition) { second result } else if(second alternative condition) { third result } else { //everything not caught by the previous conditions triggers this other result } [/code][/QUOTE] Awesome. That makes sense. Thanks! [editline]26th October 2013[/editline] [QUOTE=Tamschi;42654650]You can write any statement of block instead of the {} blocks in a if {} else {}, so you can write [code]if([...]) { [...] } else if([...]) { [...] } else { [...] }[/code] This is basically the same as [code]if([...]) { [...] } else { if([...]) { [...] } else { [...] } }[/code], just with a bit nicer formatting. (Most formatters shouldn't deepen the indentation across the "else if" line.) Please don't skip the {} on random statements though, it makes code hard to read. An if, return, continue or goto [U]on the same line[/U] are where I usually make an exception but otherwise alsmost never.[/QUOTE] Thanks. I'm always trying to look for ways to neaten up my code. It always starts to get sloppy, and it's tough for even me to follow. Granted, i don't see this becoming anything i do for money, i still enjoy finding ways to keep things looking nice. Now if only i could find a way to funnel FAFSA funding to Facepunch instead of my school. I learn more in 3 posts half the time on this site, than i do in 3 hours of lecture where we're just told what's happening, and not actually taken through what we're doing.
And to think that I moved to Linux to fix this problem. It is haunting me and making me want to throw everything out of the window. [IMG]http://img818.imageshack.us/img818/9740/f21l.jpg[/IMG] QT5 [B]EDIT:[/B] Never mind that, out of desperation compiling made it work. Now only java does not work at all
Sorry to ask you all a million questions, but do any of you code on Macbooks? I like typing up code on it, but i always end up having to send it over to my Windows Desktop to get the code compiled and run. I use Sublime Text to type it up, that a web developer friend of mine recommended, i just don't know if there's anything like Visual Basic on the Mac. It's not the worst thing, since i usually just hop on LogMeIn and paste the text onto my desktop and run it, but it's definitely not the fastest way to do things.
[QUOTE=diwako;42655394]Now only java does not work at all[/QUOTE] From the lack of information about this I presume you don't expect help with that, however if you post what this means specifically (e.g. "java: command not found" or SEGFAULT can both be considered "does not work at all", but have different causes obviously) I'm sure some people can point you in the right direction to get it fixed. [editline]26th October 2013[/editline] [QUOTE=JohnStamosFan;42655904]Sorry to ask you all a million questions, but do any of you code on Macbooks? I like typing up code on it, but i always end up having to send it over to my Windows Desktop to get the code compiled and run. I use Sublime Text to type it up, that a web developer friend of mine recommended, i just don't know if there's anything like Visual Basic on the Mac. It's not the worst thing, since i usually just hop on LogMeIn and paste the text onto my desktop and run it, but it's definitely not the fastest way to do things.[/QUOTE] I don't know ST, but from what I've heard about it I would think there is some built-in functionality to build stuff. You might need to write a [url=https://en.wikipedia.org/wiki/Makefile]Makefile[/url]. Otherwise I think XCode is a established OS X IDE. *edit:* You can also try some editors listed [url=http://facepunch.com/showthread.php?t=1250528&p=42228084&viewfull=1#post42228084]here[/url]. Other than that, you could also keep a terminal window open (perhaps you can also get one integrated in ST; I know some editors have this functionality either built-in or as plugin) and run you favourite build-tool (e.g. see Makefile). For quick single (or few) file build you can also just invoke the compiler directly, e.g. [code]$ clang++ $(pkg-config sdl2 --cflags --libs) something.cpp[/code] If you'd do something with SDL2. Is there a pkg-config for OS X? Anyway, of no concern to you if you don't work with external libraries yet.
Are there any remotely similar IDE's for python that resemble Visual Studios I'm having a hard time finding one, which in my general opinion is pretty weird considering python is very object oriented
[QUOTE=ZeekyHBomb;42655923]From the lack of information about this I presume you don't expect help with that, however if you post what this means specifically (e.g. "java: command not found" or SEGFAULT can both be considered "does not work at all", but have different causes obviously) I'm sure some people can point you in the right direction to get it fixed.[/QUOTE] It is not really a programming question, more like how to get java/eclipse/netbeans even to work on linux. I ended up deleted everything relating to java to start over and installed jre1.7.0_45 under /usr/java. But yeah, that didn't help either.
I doubt anyone will object, even if it is not directly about programming. Remove whatever you did there and use your distros package-manager to install stuff. E.g. in Debian-based distros you can do apt-get install openjdk-7-jdk to get a Java 7 runtime and development environment, and then apt-get install eclipse or apt-get install netbeans to get either of those IDEs.
[QUOTE=JohnStamosFan;42655904]Sorry to ask you all a million questions, but do any of you code on Macbooks? I like typing up code on it, but i always end up having to send it over to my Windows Desktop to get the code compiled and run. I use Sublime Text to type it up, that a web developer friend of mine recommended, i just don't know if there's anything like Visual Basic on the Mac. It's not the worst thing, since i usually just hop on LogMeIn and paste the text onto my desktop and run it, but it's definitely not the fastest way to do things.[/QUOTE] I have a Windows desktop that I use for stuff like that, but you could use Dropbox or a version control system. Or use Parallels or Bootcamp to run/emulate Windows on the Mac.
[QUOTE=ZeekyHBomb;42656339]I doubt anyone will object, even if it is not directly about programming. Remove whatever you did there and use your distros package-manager to install stuff. E.g. in Debian-based distros you can do apt-get install openjdk-7-jdk to get a Java 7 runtime and development environment, and then apt-get install eclipse or apt-get install netbeans to get either of those IDEs.[/QUOTE] Well, nope, Netbeans does not even start and eclipse cannot find java on start. [IMG]http://img818.imageshack.us/img818/8498/c0nt.jpg[/IMG]
What Distro are you using and what does Netbeans output in the terminal when you start it from there?
[QUOTE=ZeekyHBomb;42656594]What Distro are you using and what does Netbeans output in the terminal when you start it from there?[/QUOTE] Ubuntu 12.04 LTS. The above error is in both, Netbeans and Eclipse on compile. The IDE's not starting was my fault, I forgot to purge absolutely everything. Also even tho I installed JDK 7 (1.7.xx) through apt-get java and javac show version jdk 6 (1.6.0_27)
What does 'which java' output? Any try to log-out and back in (no need to restart, just log out form the session), maybe PATH wasn't updated correctly.
[QUOTE=ZeekyHBomb;42655923]From the lack of information about this I presume you don't expect help with that, however if you post what this means specifically (e.g. "java: command not found" or SEGFAULT can both be considered "does not work at all", but have different causes obviously) I'm sure some people can point you in the right direction to get it fixed. [editline]26th October 2013[/editline] I don't know ST, but from what I've heard about it I would think there is some built-in functionality to build stuff. You might need to write a [url=https://en.wikipedia.org/wiki/Makefile]Makefile[/url]. Otherwise I think XCode is a established OS X IDE. *edit:* You can also try some editors listed [url=http://facepunch.com/showthread.php?t=1250528&p=42228084&viewfull=1#post42228084]here[/url]. Other than that, you could also keep a terminal window open (perhaps you can also get one integrated in ST; I know some editors have this functionality either built-in or as plugin) and run you favourite build-tool (e.g. see Makefile). For quick single (or few) file build you can also just invoke the compiler directly, e.g. [code]$ clang++ $(pkg-config sdl2 --cflags --libs) something.cpp[/code] If you'd do something with SDL2. Is there a pkg-config for OS X? Anyway, of no concern to you if you don't work with external libraries yet.[/QUOTE] Sublime text is a fancy text editor and really should not be used for anything that isn't web development. It's not an IDE in any way. [editline]27th October 2013[/editline] [QUOTE=ZeekyHBomb;42656706]What does 'which java' output? Any try to log-out and back in (no need to restart, just log out form the session), maybe PATH wasn't updated correctly.[/QUOTE] Does installing Java on linux automatically add it to PATH? I'm fairly sure it doesn't on windows so he might have to set it manually.
[QUOTE=ZeekyHBomb;42656706]What does 'which java' output? Any try to log-out and back in (no need to restart, just log out form the session), maybe PATH wasn't updated correctly.[/QUOTE] which java after relog: "/usr/bin/java" Problem still persists in eclipse and netbeans
[QUOTE=Tamschi;42654650]You can write any statement of block instead of the {} blocks in a if {} else {}, so you can write This is basically the same as [code]if([...]) { [...] } else { if([...]) { [...] } else { [...] } }[/code], just with a bit nicer formatting. (Most formatters shouldn't deepen the indentation across the "else if" line.) Please don't skip the {} on random statements though, it makes code hard to read. An if, return, continue or goto [U]on the same line[/U] are where I usually make an exception but otherwise alsmost never.[/QUOTE] [code] //use varibables to determine age. if( age >= 65 ) { cout << "Your ticket wil be $5.00. "; } else { if(age =< 12 ) { cout << "Your ticket will be $7.00. " } else { cout << "Your ticket will be $8.00. " } } [/code] How does that look? [editline]26th October 2013[/editline] Whoops, looks like i've got a backwards >= to fix.
[QUOTE=mobrockers;42656776]Does installing Java on linux automatically add it to PATH? I'm fairly sure it doesn't on windows so he might have to set it manually.[/QUOTE] It does on a decent Distro when installed via the package manager at least :) [QUOTE=diwako;42656795]which java after relog: "/usr/bin/java" Problem still persists in eclipse and netbeans[/QUOTE] According to [url=http://packages.ubuntu.com/precise/amd64/openjdk-7-jre-headless/filelist]this file-list[/url] this is incorrect. What does 'readlink -f /usr/bin/java && file $(readlink -f /usr/bin/java)' output? This might be left over from the custom installed JRE.
[QUOTE=JohnStamosFan;42656877][code] //use varibables to determine age. if( age >= 65 ) { cout << "Your ticket wil be $5.00. "; } else { if(age =< 12 ) { cout << "Your ticket will be $7.00. " } else { cout << "Your ticket will be $8.00. " } } [/code] How does that look?[/QUOTE] [code] //use varibables to determine age. if( age >= 65 ) { cout << "Your ticket wil be $5.00. "; } else if(age <= 12 ) { cout << "Your ticket will be $7.00. "; } else { cout << "Your ticket will be $8.00. "; } [/code] This is what you want.
[QUOTE=JohnStamosFan;42656877][code] //use varibables to determine age. if( age >= 65 ) { cout << "Your ticket wil be $5.00. "; } else { if(age =< 12 ) { cout << "Your ticket will be $7.00. " } else { cout << "Your ticket will be $8.00. " } } [/code] How does that look? [editline]26th October 2013[/editline] Whoops, looks like i've got a backwards >= to fix.[/QUOTE] That "backwards >=" is <=, not =<. I'd format it like [code] if( age >= 65 ) { cout << "Your ticket wil be $5.00. "; } else if(age >= 13 ) { cout << "Your ticket will be $8.00. " } else { cout << "Your ticket will be $7.00. " }[/code] This way the age is ordered high - mid - low instead of high - low - mid.
[QUOTE=ZeekyHBomb;42656896]IAccording to [url=http://packages.ubuntu.com/precise/amd64/openjdk-7-jre-headless/filelist]this file-list[/url] this is incorrect. What does 'readlink -f /usr/bin/java && file $(readlink -f /usr/bin/java)' output? This might be left over from the custom installed JRE.[/QUOTE] [IMG]http://img585.imageshack.us/img585/4336/a4at.jpg[/IMG]
Sorry, you need to Log In to post a reply to this thread.